From ad364a2058599c1523bc39adef70000d9ec9fa82 Mon Sep 17 00:00:00 2001 From: desmonna Date: Mon, 1 Jun 2026 14:51:47 +0800 Subject: [PATCH] fix: use sys.executable instead of hardcoded 'python' for subprocess calls On Windows with multiple Python installations, hardcoded 'python' resolves to the system default (via PATH) rather than the active venv interpreter. This causes subprocess-spawned children to miss venv-installed packages. Replace all 10 occurrences of ["python", ...] with [sys.executable, ...]: - ga_cli/cli.py: 7 command entries (gui, configure, hub, tui, tui2, cli, launch) - memory/checklist_helper.py: 3 subprocess.Popen calls (bbs, worker, master) --- ga_cli/cli.py | 14 +++++++------- memory/checklist_helper.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ga_cli/cli.py b/ga_cli/cli.py index 9ecc4455c..23b81218e 100644 --- a/ga_cli/cli.py +++ b/ga_cli/cli.py @@ -48,37 +48,37 @@ def launch_frontend(cmd_parts, args=None): "gui": { "help": "启动桌面GUI (qtapp)", "desc": "启动基于 PyQt5 的完整桌面聊天界面(气泡代码高亮、文件拖拽、历史搜索)", - "cmd": ["python", "{FRONTENDS}/qtapp.py"], + "cmd": [sys.executable, "{FRONTENDS}/qtapp.py"], }, "configure": { "help": "运行初始配置向导 (configure_mykey.py)", "desc": "首次安装后配置 API Key、模型参数等基础设置", - "cmd": ["python", "{PROJECT_DIR}/assets/configure_mykey.py"], + "cmd": [sys.executable, "{PROJECT_DIR}/assets/configure_mykey.py"], }, "hub": { "help": "启动 Hub 管理器 (launcher)", "desc": "启动 hub 前端管理面板(系统托盘 + 浏览器界面)", - "cmd": ["python", "{PROJECT_DIR}/hub.pyw"], + "cmd": [sys.executable, "{PROJECT_DIR}/hub.pyw"], }, "tui": { "help": "启动终端 TUI (tuiapp)", "desc": "启动终端图形界面(Textual),适合纯终端环境或 SSH", - "cmd": ["python", "{FRONTENDS}/tuiapp.py"], + "cmd": [sys.executable, "{FRONTENDS}/tuiapp.py"], }, "tui2": { "help": "启动终端 TUI v2 (tuiapp_v2)", "desc": "启动增强版终端图形界面(Textual v2),更多功能更好的体验", - "cmd": ["python", "{FRONTENDS}/tuiapp_v2.py"], + "cmd": [sys.executable, "{FRONTENDS}/tuiapp_v2.py"], }, "cli": { "help": "启动 CLI 对话 (agentmain)", "desc": "启动命令行交互对话模式,最轻量的使用方式", - "cmd": ["python", "{PROJECT_DIR}/agentmain.py"], + "cmd": [sys.executable, "{PROJECT_DIR}/agentmain.py"], }, "launch": { "help": "启动 webview 桌面壳 (launch.pyw)", "desc": "以原生窗口形式包装 stapp Web 界面(基于 pywebview)", - "cmd": ["python", "{PROJECT_DIR}/launch.pyw"], + "cmd": [sys.executable, "{PROJECT_DIR}/launch.pyw"], }, "status": { "help": "检查运行状态", diff --git a/memory/checklist_helper.py b/memory/checklist_helper.py index 31df5a879..70b56b8b2 100644 --- a/memory/checklist_helper.py +++ b/memory/checklist_helper.py @@ -43,7 +43,7 @@ def _ensure_bbs(self): with socket.socket() as s: s.bind(('',0)); port = s.getsockname()[1] key = f"cl_{int(time.time())%1000}" (self.folder/"bbs").mkdir(exist_ok=True) - subprocess.Popen(["python", str(_BBS), "--cwd", str(self.folder/"bbs"), + subprocess.Popen([sys.executable, str(_BBS), "--cwd", str(self.folder/"bbs"), "--port", str(port), "--key", key], **_PK) time.sleep(1) self._d["bbs"] = {"url": f"http://127.0.0.1:{port}", "key": key} @@ -79,10 +79,10 @@ def start_worker(self, n=None): n = n or self.workers or 1 if n <= 0: return for i in range(n): - subprocess.Popen(["python", str(_MAIN), "--reflect", str(_W_RE), + subprocess.Popen([sys.executable, str(_MAIN), "--reflect", str(_W_RE), "--base_url", self.bbs_url, "--board_key", self.bbs_key, "--name", f"w{i+1}"], **_PK) if i < n - 1: time.sleep(5) def start_master(self): - subprocess.Popen(["python", str(_MAIN), "--reflect", str(_M_RE), + subprocess.Popen([sys.executable, str(_MAIN), "--reflect", str(_M_RE), "--mr_folder", str(self.folder.resolve())], **_PK)