1.更新ubuntu虚拟路径启动方式

This commit is contained in:
陈横 2025-10-11 11:34:20 +08:00
parent 0728bd7290
commit 7c01eb6b9e

View File

@ -120,6 +120,39 @@ class PlatformUtils:
else:
return venv_path / 'bin' / 'python'
@staticmethod
def find_venv_path(project_path: Path) -> Optional[Path]:
"""
查找项目中的虚拟环境路径
根据平台规定虚拟环境目录名称
- Windows: .venv
- Ubuntu/Linux: venv
- macOS: venv
"""
system = PlatformUtils.get_system_type()
# 根据平台确定虚拟环境目录名
if system == 'windows':
venv_name = '.venv'
else: # Linux, macOS等
venv_name = 'venv'
venv_path = project_path / venv_name
# 检查虚拟环境是否存在
if venv_path.exists() and venv_path.is_dir():
# 验证是否是有效的虚拟环境目录
python_exec = PlatformUtils.get_python_executable(venv_path)
if python_exec.exists():
print(f"找到虚拟环境: {venv_path}")
return venv_path
else:
print(f"虚拟环境目录存在但无效缺少Python解释器: {venv_path}")
return None
else:
print(f"虚拟环境不存在: {venv_path} (平台: {system})")
return None
@staticmethod
def get_pycharm_paths() -> List[Path]:
"""获取各平台PyCharm可能的安装路径"""
@ -914,16 +947,18 @@ if __name__ == "__main__":
print(f"No entry point found for project: {project_path_obj}")
return False
venv_path = project_path_obj / ".venv"
# 使用跨平台的虚拟环境查找方法
venv_path = PlatformUtils.find_venv_path(project_path_obj)
if not venv_path:
print(f"错误: 未找到虚拟环境")
return False
print(f"虚拟环境路径: {venv_path}")
print(f"脚本路径: {entry_point}")
if not venv_path.exists():
print(f"错误: 虚拟环境路径不存在: {venv_path}")
if not entry_point.exists():
print(f"错误: 脚本文件不存在: {entry_point}")
return False
print(f'target_project_path:{target_project_path}')
process, stdout, stderr = self.run_python_in_venv(str(venv_path), str(entry_point), [target_project_path])