fix: venv改为懒加载,兼容嵌入式CPython无venv模块

This commit is contained in:
qinglong
2026-06-14 19:02:27 +08:00
parent b9252bdc58
commit 2c5cd57ad4
2 changed files with 10 additions and 2 deletions
+3 -2
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""SenSu PyEnvManager — Python 版本管理 + venv + 依赖安装"""
import os, sys, subprocess, logging, venv, shutil
import os, sys, subprocess, logging, shutil
from pathlib import Path
from typing import Optional, List
@@ -76,7 +76,8 @@ class PyEnvManager:
logger.info(f"创建 venv: {venv_path} (Python {python_version or 'default'})")
try:
venv.create(str(venv_path), with_pip=True, clear=True)
import venv as _venv
_venv.create(str(venv_path), with_pip=True, clear=True)
# Install/upgrade pip
pip = str(venv_path / "bin" / "pip")
subprocess.run([pip, "install", "--upgrade", "pip"], capture_output=True, timeout=60)