diff --git a/src/main.py b/src/main.py index fd0c0ec..07e8b3e 100644 --- a/src/main.py +++ b/src/main.py @@ -8,9 +8,23 @@ CutThenThink 应用入口 import sys import os -# 添加src目录到路径 -current_dir = os.path.dirname(os.path.abspath(__file__)) -sys.path.insert(0, current_dir) +def setup_path(): + """设置Python路径,兼容开发和打包环境""" + if getattr(sys, 'frozen', False): + # PyInstaller打包后的环境 + # 在打包环境中,src目录会被解压到sys._MEIPASS + base_path = sys._MEIPASS + src_path = os.path.join(base_path, 'src') + if os.path.exists(src_path): + sys.path.insert(0, src_path) + else: + sys.path.insert(0, base_path) + else: + # 开发环境 + current_dir = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, current_dir) + +setup_path() from gui.main_window import main