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 does not use default python version under pyenv

See original GitHub issue

Issue description

The pipenv documentation states this:

If you don’t specify a Python version on the command–line, either the [requires] python_full_version or python_version will be selected automatically, falling back to whatever your system’s default python installation is, at time of execution.

However with 2020.06.02 I’m seeing pipenv choose the most recent pyenv installed python rather than the one that’s current the default when I run pipenv install.

Expected result

Python version is 3.7.7 as set by .python-version via pyenv. I’ve verified that pipenv is installed and running from 3.7.7. I start a new project with pipenv install and I expect to see a virtual environment created with Python version 3.7.7.

artlogic@wardenclyffe:~/Code/random/pipenv-again$ python -V
Python 3.7.7
artlogic@wardenclyffe:~/Code/random/pipenv-again$ pipenv --support
<details><summary>$ pipenv --support</summary>

Pipenv version: `'2020.6.2'`

Pipenv location: `'/home/artlogic/.pyenv/root/versions/3.7.7/lib/python3.7/site-packages/pipenv'`

Python location: `'/home/artlogic/.pyenv/root/versions/3.7.7/bin/python3.7'`

Actual result

pipenv uses a different pyenv installed python to create the venv:

artlogic@wardenclyffe:~/Code/random/pipenv-again$ pipenv install -v requests
Using python: None
Path to python: /home/artlogic/.pyenv/root/versions/3.8.2/bin/python3
Creating a virtualenv for this project…
Pipfile: /home/artlogic/Code/random/pipenv-again/Pipfile
Using /home/artlogic/.pyenv/root/versions/3.8.2/bin/python3 (3.8.2) to create virtualenv…

Steps to replicate

  1. Install two versions of python using pyenv (3.7.7 and 3.8.3).
  2. Make a project directory and type: pyenv local 3.7.7 (verify you’re now using 3.7.7)
  3. Install pipenv: pip install pipenv
  4. Install a dependency: pipenv install requests
  5. Watch the virtualenv get created with 3.8.3.

$ pipenv --support

Pipenv version: '2020.6.2'

Pipenv location: '/home/artlogic/.pyenv/root/versions/3.7.7/lib/python3.7/site-packages/pipenv'

Python location: '/home/artlogic/.pyenv/root/versions/3.7.7/bin/python3.7'

Python installations found:

  • 3.8.2: /home/artlogic/.pyenv/root/versions/3.8.2/bin/python3
  • 3.7.7: /home/artlogic/.pyenv/root/versions/3.7.7/bin/python3
  • 3.7.7: /home/artlogic/.pyenv/root/versions/3.7.7/bin/python3.7m
  • 3.7.7: /home/artlogic/.pyenv/root/versions/3.7.7/bin/python3.7
  • 3.7.7: /home/artlogic/.pyenv/root/versions/3.7.7/bin/python3
  • 3.7.5: /home/artlogic/.pyenv/root/versions/3.7.5/bin/python3
  • 3.7.4: /home/artlogic/.pyenv/root/versions/3.7.4/bin/python3
  • 3.7.3: /home/artlogic/.pyenv/root/versions/3.7.3/bin/python3
  • 3.7.2: /home/artlogic/.pyenv/root/versions/3.7.2/bin/python3
  • 3.7.0: /home/artlogic/.pyenv/root/versions/3.7.0/bin/python3
  • 3.6.3: /home/artlogic/.pyenv/root/versions/3.6.3/bin/python3
  • 3.6.1: /home/artlogic/.pyenv/root/versions/3.6.1/bin/python3
  • 3.5.4: /home/artlogic/.pyenv/root/versions/3.5.4/bin/python3
  • 3.5.3: /usr/bin/python3
  • 3.5.3: /usr/bin/python3.5
  • 3.5.3: /usr/bin/python3.5m
  • 2.7.15: /home/artlogic/.pyenv/root/versions/2.7.15/bin/python2
  • 2.7.14: /home/artlogic/.pyenv/root/versions/2.7.14/bin/python2
  • 2.7.13: /usr/bin/python2
  • 2.7.13: /usr/bin/python2.7

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '3.7.7',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '4.9.0-12-amd64',
 'platform_system': 'Linux',
 'platform_version': '#1 SMP Debian 4.9.210-1 (2020-01-20)',
 'python_full_version': '3.7.7',
 'python_version': '3.7',
 'sys_platform': 'linux'}

System environment variables:

  • CLUTTER_IM_MODULE
  • PIPENV_VENV_IN_PROJECT
  • NVM_DIR
  • LS_COLORS
  • XDG_MENU_PREFIX
  • LANG
  • GDM_LANG
  • DISPLAY
  • PYENV_ROOT
  • OLDPWD
  • COLORTERM
  • NVM_CD_FLAGS
  • USERNAME
  • PYENV_VIRTUALENV_INIT
  • PYENV_HOOK_PATH
  • XDG_VTNR
  • SSH_AUTH_SOCK
  • XDG_SESSION_ID
  • USER
  • PYENV_DIR
  • DESKTOP_SESSION
  • RBENV_SHELL
  • QT4_IM_MODULE
  • QT_QPA_PLATFORMTHEME
  • PWD
  • HOME
  • JOURNAL_STREAM
  • SSH_AGENT_PID
  • PYENV_VERSION
  • QT_ACCESSIBILITY
  • XDG_SESSION_TYPE
  • XDG_DATA_DIRS
  • XDG_SESSION_DESKTOP
  • GJS_DEBUG_OUTPUT
  • GTK_MODULES
  • WINDOWPATH
  • VTE_VERSION
  • TERM
  • SHELL
  • RBENV_ROOT
  • QT_IM_MODULE
  • XMODIFIERS
  • NVM_BIN
  • XDG_CURRENT_DESKTOP
  • GPG_AGENT_INFO
  • QT_LINUX_ACCESSIBILITY_ALWAYS_ON
  • XDG_SEAT
  • SHLVL
  • PYENV_SHELL
  • WINDOWID
  • GDMSESSION
  • GNOME_DESKTOP_SESSION_ID
  • LOGNAME
  • DBUS_SESSION_BUS_ADDRESS
  • XDG_RUNTIME_DIR
  • XAUTHORITY
  • PATH
  • NVM_INC
  • GJS_DEBUG_TOPICS
  • SESSION_MANAGER
  • GTK_IM_MODULE
  • PIP_DISABLE_PIP_VERSION_CHECK
  • PYTHONDONTWRITEBYTECODE
  • PIP_SHIMS_BASE_MODULE
  • PIP_PYTHON_PATH
  • PYTHONFINDER_IGNORE_UNSUPPORTED

Pipenv–specific environment variables:

  • PIPENV_VENV_IN_PROJECT: 1

Debug–specific environment variables:

  • PATH: /home/artlogic/.pyenv/root/versions/3.7.7/bin:/home/artlogic/.pyenv/root/libexec:/home/artlogic/.pyenv/root/plugins/python-build/bin:/home/artlogic/.rbenv/root/shims:/home/artlogic/.rbenv/root/bin:/home/artlogic/.rbenv/ruby-build/bin:/home/artlogic/.pyenv/pyenv-virtualenv/shims:/home/artlogic/.pyenv/root/shims:/home/artlogic/.pyenv/root/bin:/home/artlogic/.pyenv/pyenv-virtualenv/bin:/home/artlogic/.dotfiles/config/.nvm/versions/node/v12.16.3/bin:/home/artlogic/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
  • SHELL: /bin/bash
  • LANG: en_US.UTF-8
  • PWD: /home/artlogic/Code/random/pipenv-again

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
ghostcommented, Jul 21, 2020

Yes, Pipenv uses a different finding approach that the highest version goes first. You can anyway pass the python version by pipenv install --python=3.7.

Please change this behaviour. It is very unexpected. When you specify --python 3.8 it can happen on MacOS, that it uses 3.8.4 from homebrew instead of the 3.8.3 from pyenv. Pyenv can lag a bit, but homebrew changes the default python version and removes the previous one without any warning, which is why many of us use pyenv, so they have control over the versions installed and know when to update virtualenvs at their own pace.

It also goes against the notion of python3.8 -m <module> where one expects the module to use the python version of that it is installed in. It technically does, but it’s unexpected that it switches versions for virtual env selection.

Last but not least, pinning my Pipfile to a version gets trickled to source repositories, which then trickles to CI/CD pipefiles and complicates that workflow, when a CI tests against multiple python versions. One normally would use pipenv --deploy, but that won’t work if Pipfile is pinned against a specific version.

6reactions
artlogiccommented, Jun 15, 2020

Would you accept a PR to update the docs for the time being?

This does feel like a bit of a UX regression to me. I found it very unexpected that pipenv chose a python that wasn’t my current default to make the virtualenv. If you wouldn’t mind, what’s the rationale behind this change?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pipenv not recognizing Pyenv version? - python - Stack Overflow
Pipenv is aware of Pyenv, but it doesn't automatically use the same Python version unless you tell it to do that. There is...
Read more >
How to Manage your Python Projects with Pipenv and Pyenv
Pyenv is a tool used to manage different Python versions. With this tool you can: Install several Python versions. Set/change the global(default) ...
Read more >
Frequently Encountered Pipenv Problems - Read the Docs
☤ Pipenv does not respect pyenv's global and local Python versions. Pipenv by default uses the Python it is installed against to create...
Read more >
How to install pyenv+pipenv in ubuntu and use multiple ...
pyenv allows each version of python on our computer to be managed separately, and pipenv can create a new independent package-space under each...
Read more >
Python Environment 101 - Towards Data Science
You can use pyenv and pipenv in your Python projects and in this article ... pyenv is for a Python version management +...
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