获取已安装 Python 环境中的可执行文件路径
(base_dir, os_type)
| 68 | |
| 69 | |
| 70 | def get_python_executable_path(base_dir, os_type): |
| 71 | """获取已安装 Python 环境中的可执行文件路径""" |
| 72 | if os_type == "Windows": |
| 73 | return os.path.join(base_dir, "python.exe") |
| 74 | elif os_type == "Darwin": # macOS |
| 75 | # python-build-standalone 通常包含 python 和 python3 |
| 76 | # 我们优先使用 python3 (通常 python 是指向 python3 的符号链接) |
| 77 | py3_path = os.path.join(base_dir, "bin", "python3") |
| 78 | py_path = os.path.join(base_dir, "bin", "python") |
| 79 | if os.path.exists(py3_path): |
| 80 | return py3_path |
| 81 | elif os.path.exists(py_path): # 作为备选 |
| 82 | return py_path |
| 83 | else: |
| 84 | return None # 未找到 |
| 85 | return None |
| 86 | |
| 87 | |
| 88 | def ensure_pip(python_executable, python_install_dir): |