Skip to content

Commit 74e6f63

Browse files
committed
fix(environment): update python executable lookup
This fix resolves a faulty path on MSYS2 MinGW CPython, where the bin/ segment is missing altogether. This is required by the uninstall routine. It also simplifies the lookup on all other platforms. As far as I comprehended, the condition in line 255 would never be met, as the joinpath('python') in line 254 guarantees that py will never become a false-equivalent value, since its definition is in the else statement, hence catches the unmatched condition in line 251. I've also inverted the condition of checking for self._python, so that an intermediate assignment to `py` is no longer required.
1 parent 3babe0a commit 74e6f63

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

pipenv/environment.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pipenv.utils.indexes import prepare_pip_source_args
2727
from pipenv.utils.processes import subprocess_run
2828
from pipenv.utils.shell import temp_environ
29+
from pipenv.utils.virtualenv import virtualenv_scripts_dir
2930
from pipenv.vendor.importlib_metadata.compat.py39 import normalized_name
3031
from pipenv.vendor.pythonfinder.utils import is_in_path
3132

@@ -246,16 +247,12 @@ def script_basedir(self) -> str:
246247
@property
247248
def python(self) -> str:
248249
"""Path to the environment python"""
249-
if self._python is not None:
250-
return self._python
251-
if os.name == "nt" and not self.is_venv:
252-
py = Path(self.prefix).joinpath("python").absolute().as_posix()
253-
else:
254-
py = Path(self.script_basedir).joinpath("python").absolute().as_posix()
255-
if not py:
256-
py = Path(sys.executable).as_posix()
257-
self._python = py
258-
return py
250+
if self._python is None:
251+
self._python = (
252+
(virtualenv_scripts_dir(self.prefix) / "python").absolute().as_posix()
253+
)
254+
255+
return self._python
259256

260257
@cached_property
261258
def sys_path(self) -> list[str]:

0 commit comments

Comments
 (0)