question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pipenv install --system fails when `python` points to Python 2.

See original GitHub issue

Issue description

Since 2022.8.15 pipenv install --system will fail on systems that have both Python 2 and Python 3 installed but which python resolves to Python 2. In commit dbea3f5 it switched from using project._which() which uses sys.executable to determine which python to run to using python_project() which, when using --system first checks for python and then python3. So if, e.g. your project/system is using Python 3 which is installed as /usr/local/bin/python3 but your system Python package us Python 2 which is at /usr/bin/python then it will try to execute using Python 2, resulting in

[pipenv.exceptions.InstallError]: File "/git-test/pipenv/patched/pip/__pip-runner__.py", line 21
[pipenv.exceptions.InstallError]:     fullname: str,
[pipenv.exceptions.InstallError]:             ^
[pipenv.exceptions.InstallError]: SyntaxError: invalid syntax

Expected result

Expected result is pipenv install --system installs the dependencies using Python 3. Although I’m not sure it’s really a bug since technically it is using the β€œsystem” Python. Nevertheless it is a regression.

Actual result

# python3 -m pipenv install  --system --verbose
Installing dependencies from Pipfile.lock (89d195)...
Writing supplied requirement line to temporary file: "dataclasses==0.8; python_version < '3.7' --hash=sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97 --hash=sha256:0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf"
Installing 'dataclasses'
$ /usr/bin/python /usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py install --verbose --upgrade --require-hashes --no-deps --exists-action=i -r /tmp/pipenv-v0jrsbzs-requirements/pipenv-_x_y9mvb-requirement.txt
Writing supplied requirement line to temporary file: "importlib-metadata==4.8.2; python_version < '3.8' --hash=sha256:53ccfd5c134223e497627b9815d5030edf77d2ed573922f7a0b8f8bb81a1c100 --hash=sha256:75bdec14c397f528724c1bfd9709d660b33a4d2e77387a3358f20b848bb5e5fb"
Installing 'importlib-metadata'
$ /usr/bin/python /usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py install --verbose --upgrade --require-hashes --no-deps --exists-action=i -r /tmp/pipenv-v0jrsbzs-requirements/pipenv-y_uqgaka-requirement.txt
Writing supplied requirement line to temporary file: "typing-extensions==4.0.1; python_version < '3.8' --hash=sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b --hash=sha256:4ca091dea149f945ec56afb48dae714f21e8692ef22a395223bcd328961b6a0e"
Installing 'typing-extensions'
$ /usr/bin/python /usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py install --verbose --upgrade --require-hashes --no-deps --exists-action=i -r /tmp/pipenv-v0jrsbzs-requirements/pipenv-k8di4opm-requirement.txt
  🐍   β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰ 3/3 β€” 00:00:00
File "/usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py", line 21
    fullname: str,
            ^
SyntaxError: invalid syntax
An error occurred while installing dataclasses==0.8; python_version < '3.7' --hash=sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97 --hash=sha256:0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf! Will try again.
File "/usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py", line 21
    fullname: str,
            ^
SyntaxError: invalid syntax
An error occurred while installing importlib-metadata==4.8.2; python_version < '3.8' --hash=sha256:53ccfd5c134223e497627b9815d5030edf77d2ed573922f7a0b8f8bb81a1c100 --hash=sha256:75bdec14c397f528724c1bfd9709d660b33a4d2e77387a3358f20b848bb5e5fb! Will try again.
File "/usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py", line 21
    fullname: str,
            ^
SyntaxError: invalid syntax
An error occurred while installing typing-extensions==4.0.1; python_version < '3.8' --hash=sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b --hash=sha256:4ca091dea149f945ec56afb48dae714f21e8692ef22a395223bcd328961b6a0e! Will try again.
Installing initially failed dependencies...
Writing supplied requirement line to temporary file: "dataclasses==0.8; python_version < '3.7' --hash=sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97 --hash=sha256:0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf"
Installing 'dataclasses'
$ /usr/bin/python /usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py install --verbose --upgrade --require-hashes --no-use-pep517 --no-deps --exists-action=i -r /tmp/pipenv-v0jrsbzs-requirements/pipenv-x1ek7nrg-requirement.txt
Writing supplied requirement line to temporary file: "importlib-metadata==4.8.2; python_version < '3.8' --hash=sha256:53ccfd5c134223e497627b9815d5030edf77d2ed573922f7a0b8f8bb81a1c100 --hash=sha256:75bdec14c397f528724c1bfd9709d660b33a4d2e77387a3358f20b848bb5e5fb"
Installing 'importlib-metadata'
$ /usr/bin/python /usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py install --verbose --upgrade --require-hashes --no-use-pep517 --no-deps --exists-action=i -r /tmp/pipenv-v0jrsbzs-requirements/pipenv-iyfa0tgp-requirement.txt
Writing supplied requirement line to temporary file: "typing-extensions==4.0.1; python_version < '3.8' --hash=sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b --hash=sha256:4ca091dea149f945ec56afb48dae714f21e8692ef22a395223bcd328961b6a0e"
Installing 'typing-extensions'
$ /usr/bin/python /usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py install --verbose --upgrade --require-hashes --no-use-pep517 --no-deps --exists-action=i -r /tmp/pipenv-v0jrsbzs-requirements/pipenv-jmqhat8h-requirement.txt
File "/usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py", line 21
    fullname: str,
            ^
SyntaxError: invalid syntax
[pipenv.exceptions.InstallError]: File "/usr/local/lib/python3.9/site-packages/pipenv/patched/pip/__pip-runner__.py", line 21
[pipenv.exceptions.InstallError]:     fullname: str,
[pipenv.exceptions.InstallError]:             ^
[pipenv.exceptions.InstallError]: SyntaxError: invalid syntax
ERROR: Couldn't install package: dataclasses
 Package installation failed...
/usr/local/lib/python3.9/subprocess.py:1052: ResourceWarning: subprocess 742 is still running
  _warn("subprocess %s is still running" % self.pid,
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=6 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=9 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
  ☀  β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰ 2/3 β€” 00:00:00
/usr/local/lib/python3.9/subprocess.py:1052: ResourceWarning: subprocess 741 is still running
  _warn("subprocess %s is still running" % self.pid,
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name=4 encoding='utf-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name=7 encoding='utf-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback

Steps to replicate

  • Prepare a container, e.g. a CentOS container that has Python 2.7 as the system python.
  • Install Python 3 into /usr/local but ensure there is no /usr/local/bin/python
  • Create a simple Pipfile then pipenv install --system

Please run $ pipenv --support, and paste the results here. Don’t put backticks (`) around it! The output already contains Markdown formatting.

I can not paste the actual output but please let me know if you still need it and I will try to come up with a trivial reproducer.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
enkucommented, Aug 25, 2022

I haven’t tried to see if this breaks anything else, but this simple change worked for me:

diff --git a/pipenv/utils/shell.py b/pipenv/utils/shell.py
index 362290fa..f6e39bd0 100644
--- a/pipenv/utils/shell.py
+++ b/pipenv/utils/shell.py
@@ -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:
0reactions
matteiuscommented, Aug 30, 2022

pipenv, version 2022.8.30 has been released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is pipenv telling me the wrong version of python?
It scans your system and looks for a compatible python installation. Now, it seems you already have an existing Pipfile that has "2.7"...
Read more >
Common Pipenv Errors and How to Solve Them: Why Won't it ...
The second most common reason locking fails is that we attempt to install a package that is a pre-release version. You can resolve...
Read more >
pipenv Documentation - Read the Docs
Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the. Python...
Read more >
Advanced Usage of Pipenv - Read the Docs
Pipenv allows you to open any Python module that is installed (including ones in your codebase), with the $ pipenv open command: $...
Read more >
Release and Version History β€” pipenv 2022.12.20.dev0 ...
Fix an issue when using pipenv install --system on systems that having the python executable pointing to Python 2 and a Python 3...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found