From 37f91c4b8cd6ab80619276d2cf9d838ebcd41714 Mon Sep 17 00:00:00 2001 From: milk <53408947@qq.com> Date: Mon, 17 Nov 2025 19:42:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AF=81=E4=B9=A6=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Module/Main.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Module/Main.py b/Module/Main.py index 35694d7..e214067 100644 --- a/Module/Main.py +++ b/Module/Main.py @@ -43,11 +43,17 @@ def _run_flask_role(): # 把 WSGI Flask app 包成 ASGI app asgi_app = WsgiToAsgi(app) - # Hypercorn 配置 - # 自动定位 resources 目录 - base_dir = os.path.dirname(os.path.abspath(__file__)) # 当前 py 的目录(Module/) - project_root = os.path.dirname(base_dir) # 回到项目根目录(iOSAi/) - resource_dir = os.path.join(project_root, "resources") # 拼到 resources + # ==== 关键:统一获取 resources 目录 ==== + if "__compiled__" in globals(): + # 被 Nuitka 编译后的 exe 运行时 + base_dir = os.path.dirname(sys.executable) # exe 所在目录 + else: + # 开发环境,直接跑 .py + cur_file = os.path.abspath(__file__) # Module/Main.py 所在目录 + base_dir = os.path.dirname(os.path.dirname(cur_file)) # 回到项目根 iOSAi + + resource_dir = os.path.join(base_dir, "resources") + config = Config() config.bind = [f"0.0.0.0:{flaskPort}"]