未验证 提交 7bd4f28b 编写于 作者: F Frost Ming

fix: fix a crash issue when pip is not installed

Fix #1269
上级 35f12d5b
......@@ -213,7 +213,10 @@ class Environment:
"""Get a pip command for this environment, and download one if not available.
Return a list of args like ['python', '-m', 'pip']
"""
from pip import __file__ as pip_location
try:
from pip import __file__ as pip_location
except ImportError:
pip_location = None # type: ignore
python_version = self.interpreter.version
executable = str(self.interpreter.executable)
......@@ -223,7 +226,7 @@ class Environment:
if proc.returncode == 0:
# The pip has already been installed with the executable, just use it
command = [executable, "-Esm", "pip"]
elif is_pip_compatible_with_python(python_version):
elif pip_location and is_pip_compatible_with_python(python_version):
# Use the host pip package if available
command = [executable, "-Es", os.path.dirname(pip_location)]
else:
......
......@@ -460,4 +460,4 @@ def is_pip_compatible_with_python(python_version: Version | str) -> bool:
pip = importlib_metadata.distribution("pip")
requires_python = get_specifier(pip.metadata["Requires-Python"])
return requires_python.contains(python_version)
return requires_python.contains(python_version, True)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册