From 0e629d38996dfe8d989a53ef49eebff9aa6ae8c0 Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Tue, 16 Aug 2022 01:04:50 -0700 Subject: [PATCH] Actually filter out missing interpreters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes https://github.com/pypa/pipenv/issues/5261. Before this change, I would get a "The Python interpreter can't be found" error when running `pipenv install --system` with a python3 but no python. Demo: ``` $ docker run $(docker build -q -f Dockerfile.pipenv-2022.8.15 https://github.com/jfly/2022-08-16-pipenv-system-which-issue.git#main) Installing dependencies from Pipfile.lock (63bec0)... The Python interpreter can't be found.▉ 0/4 — 00:00:00 🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/4 — 00:00:00 ``` I'm confident this bug was introduced in https://github.com/pypa/pipenv/commit/f276360dfcef3200908e2c6569567d617919c63d, which removed a usage of `first()`, but broke the "filter None values" behavior that `first()` gave us. --- news/5261.bugfix | 1 + pipenv/utils/shell.py | 1 + 2 files changed, 2 insertions(+) create mode 100644 news/5261.bugfix diff --git a/news/5261.bugfix b/news/5261.bugfix new file mode 100644 index 0000000000..d30c2823cc --- /dev/null +++ b/news/5261.bugfix @@ -0,0 +1 @@ +Fix "The Python interpreter can't be found" error when running `pipenv install --system` with a python3 but no python. diff --git a/pipenv/utils/shell.py b/pipenv/utils/shell.py index 030fb19b2e..362290fae9 100644 --- a/pipenv/utils/shell.py +++ b/pipenv/utils/shell.py @@ -446,6 +446,7 @@ def project_python(project, system=False): python = project._which("python") else: interpreters = [system_which(p) for p in ("python", "python3")] + interpreters = [i for i in interpreters if i] # filter out not found interpreters python = interpreters[0] if interpreters else None if not python: click.secho("The Python interpreter can't be found.", fg="red", err=True)