Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/5296.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix an issue when using ``pipenv install --system`` on systems that having the ``python`` executable pointing to Python 2 and a Python 3 executable being ``python3``.
2 changes: 1 addition & 1 deletion pipenv/utils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def project_python(project, system=False):
if not system:
python = project._which("python")
else:
interpreters = [system_which(p) for p in ("python", "python3")]
interpreters = [system_which(p) for p in ("python3", "python")]
interpreters = [i for i in interpreters if i] # filter out not found interpreters
python = interpreters[0] if interpreters else None
if not python:
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,17 @@ def test_invalid_prepare_pip_source_args(self):
sources = [{}]
with pytest.raises(PipenvUsageError):
indexes.prepare_pip_source_args(sources, pip_args=None)

@pytest.mark.utils
def test_project_python_tries_python3_before_python_if_system_is_true(self):
def mock_shutil_which(command, path=None):
if command != "python3":
return f"/usr/bin/{command}"
return "/usr/local/bin/python3"

with mock.patch("pipenv.utils.shell.shutil.which", wraps=mock_shutil_which):
# Setting project to None as system=True doesn't use it
project = None
python = shell.project_python(project, system=True)

assert python == "/usr/local/bin/python3"