pyenv / pyenv-virtualenv

a pyenv plugin to manage virtualenv (a.k.a. python-virtualenv)
MIT License
6.37k stars 403 forks source link

`$VIRTUAL_ENV/bin` is not prepended to `$PATH` #412

Closed georgevreilly closed 2 years ago

georgevreilly commented 2 years ago

Too many issues will kill our team's development velocity, drastically. Make sure you have checked all steps below.

Prerequisite

Description

Problem

pyenv-virtualenv 1.1.5 does not update PATH, unlike traditional virtualenv activation. In other words, $VIRTUAL_ENV/bin is not prepended to $PATH.

System Python: can't import pudb (as expected).

❯ python -c 'import pudb'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named pudb

~ on ☁️  (us-east-1)

I created venv310 with pyenv-virtualenv and did pip install pudb.

Activate venv310 using the traditional method. PATH is adjusted.

❯ source $PYENV_ROOT/versions/3.10.0/envs/venv310/bin/activate

~ via 🐍 v3.10.0 (venv310) on ☁️  (us-east-1)
❯ python -c 'import pudb'

~ via 🐍 v3.10.0 (venv310) on ☁️  (us-east-1)
❯ which pudb3
/Users/georgevreilly/.pyenv/versions/3.10.0/envs/venv310/bin/pudb3

~ via 🐍 v3.10.0 (venv310) on ☁️  (us-east-1)
❯ echo "$PATH" | sed -e 's/:/\n/g' | grep pyenv
/Users/georgevreilly/.pyenv/versions/3.10.0/envs/venv310/bin
/opt/homebrew/Cellar/pyenv-virtualenv/1.1.5/shims
/Users/georgevreilly/.pyenv/shims
/Users/georgevreilly/.pyenv/bin

~ via 🐍 v3.10.0 (venv310) on ☁️  (us-east-1)
❯ deactivate

~ on ☁️  (us-east-1)

Activate venv310 with pyenv-virtualenv. import pudb works but PATH is not adjusted.

❯ pyenv activate venv310
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(venv310)
~ via 🐍 v3.10.0 (venv310) on ☁️  (us-east-1)
❯ python -c 'import pudb'
(venv310)
~ via 🐍 v3.10.0 (venv310) on ☁️  (us-east-1)
❯ which pudb3
pudb3 not found
(venv310)
~ via 🐍 v3.10.0 (venv310) on ☁️  (us-east-1)
❯ echo "$PATH" | sed -e 's/:/\n/g' | grep pyenv
/opt/homebrew/Cellar/pyenv-virtualenv/1.1.5/shims
/Users/georgevreilly/.pyenv/shims
/Users/georgevreilly/.pyenv/bin
(venv310)
~ via 🐍 v3.10.0 (venv310) on ☁️  (us-east-1)
❯ pyenv deactivate

~ on ☁️  (us-east-1)
georgevreilly commented 2 years ago

Looking at rbenv, I discovered the which and exec commands. So pyenv which pudb3 and pyenv exec pudb3 -h work with pyenv-virtualenv.

native-api commented 2 years ago

This is by design. Shims dynamically select the correct executable without the need to alter PATH.