From 768aca034b4d1705f73c39f7314b9f4470d8c552 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. --- pipenv/utils/shell.py | 1 + 1 file changed, 1 insertion(+) 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)