Description
When using pyenv to manage Python versions, virtualenv's builtin discovery resolves pyenv shims to the system Python instead of the pyenv-managed version. For example, with pyenv providing Python 3.8.12 on $PATH, virtualenv resolves the shim to /usr/bin/python3.8 (system Python 3.8.6).
Originally reported as tox-dev/tox#3064, but the issue is in virtualenv's discovery logic, not tox.
Steps to Reproduce
- Install a Python version via pyenv (e.g.
pyenv install 3.8.12)
- Set it as local version (
pyenv local 3.8.12)
- Confirm
python3.8 --version returns 3.8.12
- Have a different system Python 3.8 installed (e.g.
/usr/bin/python3.8 = 3.8.6)
- Create a virtualenv targeting
python3.8
The virtualenv will use the system Python 3.8.6 instead of the pyenv-managed 3.8.12.
Verbose Discovery Log
From the original report, running tox -rvvve py38 shows virtualenv's discovery:
py38: discover exe for PythonInfo(spec=CPython3.10.6) in /usr
py38: discover PATH[0]=/home/user/.pyenv/plugins/pyenv-virtualenv/shims
py38: discover PATH[1]=/home/user/.pyenv/shims
py38: got python info of %s from (PosixPath('/home/user/.pyenv/shims/python3.8'), ...)
py38: got python info of %s from (PosixPath('/usr/bin/python3.8'), ...)
py38: proposed PathPythonInfo(spec=CPython3.8.6.final.0-64, system=/usr/bin/python3.8, exe=/home/user/.pyenv/shims/python3.8, ...)
py38: accepted PathPythonInfo(spec=CPython3.8.6.final.0-64, system=/usr/bin/python3.8, ...)
The shim at /home/user/.pyenv/shims/python3.8 is found first, but when resolving to get PythonInfo, it resolves system=/usr/bin/python3.8 (3.8.6) instead of the pyenv-managed /home/user/.pyenv/versions/3.8.12/bin/python3.8.
Expected Behavior
virtualenv should resolve pyenv shims to the actual Python they delegate to, respecting pyenv's version selection (.python-version, PYENV_VERSION, etc.), rather than resolving to the system Python.
Environment
- OS: Ubuntu (Linux)
- pyenv with pyenv-virtualenv plugin
- virtualenv 20.23.1 (at time of original report)
- Both system Python 3.8.6 and pyenv Python 3.8.12 installed
Description
When using pyenv to manage Python versions, virtualenv's builtin discovery resolves pyenv shims to the system Python instead of the pyenv-managed version. For example, with pyenv providing Python 3.8.12 on
$PATH, virtualenv resolves the shim to/usr/bin/python3.8(system Python 3.8.6).Originally reported as tox-dev/tox#3064, but the issue is in virtualenv's discovery logic, not tox.
Steps to Reproduce
pyenv install 3.8.12)pyenv local 3.8.12)python3.8 --versionreturns 3.8.12/usr/bin/python3.8= 3.8.6)python3.8The virtualenv will use the system Python 3.8.6 instead of the pyenv-managed 3.8.12.
Verbose Discovery Log
From the original report, running
tox -rvvve py38shows virtualenv's discovery:The shim at
/home/user/.pyenv/shims/python3.8is found first, but when resolving to getPythonInfo, it resolvessystem=/usr/bin/python3.8(3.8.6) instead of the pyenv-managed/home/user/.pyenv/versions/3.8.12/bin/python3.8.Expected Behavior
virtualenv should resolve pyenv shims to the actual Python they delegate to, respecting pyenv's version selection (
.python-version,PYENV_VERSION, etc.), rather than resolving to the system Python.Environment