pipenv: pipenv does not use default python version under pyenv
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
- Install two versions of python using pyenv (3.7.7 and 3.8.3).
- Make a project directory and type: pyenv local 3.7.7 (verify you’re now using 3.7.7)
- Install pipenv: pip install pipenv
- Install a dependency: pipenv install requests
- 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/python33.7.7:/home/artlogic/.pyenv/root/versions/3.7.7/bin/python33.7.7:/home/artlogic/.pyenv/root/versions/3.7.7/bin/python3.7m3.7.7:/home/artlogic/.pyenv/root/versions/3.7.7/bin/python3.73.7.7:/home/artlogic/.pyenv/root/versions/3.7.7/bin/python33.7.5:/home/artlogic/.pyenv/root/versions/3.7.5/bin/python33.7.4:/home/artlogic/.pyenv/root/versions/3.7.4/bin/python33.7.3:/home/artlogic/.pyenv/root/versions/3.7.3/bin/python33.7.2:/home/artlogic/.pyenv/root/versions/3.7.2/bin/python33.7.0:/home/artlogic/.pyenv/root/versions/3.7.0/bin/python33.6.3:/home/artlogic/.pyenv/root/versions/3.6.3/bin/python33.6.1:/home/artlogic/.pyenv/root/versions/3.6.1/bin/python33.5.4:/home/artlogic/.pyenv/root/versions/3.5.4/bin/python33.5.3:/usr/bin/python33.5.3:/usr/bin/python3.53.5.3:/usr/bin/python3.5m2.7.15:/home/artlogic/.pyenv/root/versions/2.7.15/bin/python22.7.14:/home/artlogic/.pyenv/root/versions/2.7.14/bin/python22.7.13:/usr/bin/python22.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_MODULEPIPENV_VENV_IN_PROJECTNVM_DIRLS_COLORSXDG_MENU_PREFIXLANGGDM_LANGDISPLAYPYENV_ROOTOLDPWDCOLORTERMNVM_CD_FLAGSUSERNAMEPYENV_VIRTUALENV_INITPYENV_HOOK_PATHXDG_VTNRSSH_AUTH_SOCKXDG_SESSION_IDUSERPYENV_DIRDESKTOP_SESSIONRBENV_SHELLQT4_IM_MODULEQT_QPA_PLATFORMTHEMEPWDHOMEJOURNAL_STREAMSSH_AGENT_PIDPYENV_VERSIONQT_ACCESSIBILITYXDG_SESSION_TYPEXDG_DATA_DIRSXDG_SESSION_DESKTOPGJS_DEBUG_OUTPUTGTK_MODULESWINDOWPATHVTE_VERSIONTERMSHELLRBENV_ROOTQT_IM_MODULEXMODIFIERSNVM_BINXDG_CURRENT_DESKTOPGPG_AGENT_INFOQT_LINUX_ACCESSIBILITY_ALWAYS_ONXDG_SEATSHLVLPYENV_SHELLWINDOWIDGDMSESSIONGNOME_DESKTOP_SESSION_IDLOGNAMEDBUS_SESSION_BUS_ADDRESSXDG_RUNTIME_DIRXAUTHORITYPATHNVM_INCGJS_DEBUG_TOPICSSESSION_MANAGERGTK_IM_MODULEPIP_DISABLE_PIP_VERSION_CHECKPYTHONDONTWRITEBYTECODEPIP_SHIMS_BASE_MODULEPIP_PYTHON_PATHPYTHONFINDER_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/gamesSHELL:/bin/bashLANG:en_US.UTF-8PWD:/home/artlogic/Code/random/pipenv-again
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 12
- Comments: 16 (4 by maintainers)
Please change this behaviour. It is very unexpected. When you specify
--python 3.8it 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.I’m curious to know how you’ve install
pipenv? From their documentation, it is NOT recommended that you use an external package manager such as Homebrew, but instead to usepipx. This is further complicated with the use of virtual environments. The way I got this to work is:pyenv.pyenvinto my shell RC script.pyenv global X.Yto point to the correct python version.pip install --user pipxpython -m pipx ensurepath<- we can’t yet referencepipxfrom our$PATHuntil we run this.pipx install pipenv<- you’ll need to run this for every virtual environment you needpipenvsupport.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?
I recognize this frustration, however, I worked around it by having
alias pipenv='pipenv --python=$(which python)'in my profile, as thePIPENV_DEFAULT_PYTHON_VERSIONwas not respected all of the time.