pyenv virtualenv activate doesn't change $PATH
mprat opened this issue · comments
System:
- Ubuntu 20.04, fresh install
- pyenv installed with https://github.com/pyenv/pyenv-installer
- using bash shell. the only place pyenv configurations are stored is in
.bash_profile
with these lines at the bottom:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
I created a virtual environment with the following:
pyenv install 3.9.7
pyenv virtualenv 3.9.7 testenv
Now when I try to activate the virtualenv with pyenv activate testenv
, I get the following:
[mprat@europa] $ pyenv activate testenv
(testenv) [mprat@europa] $ which python
/home/mprat/.pyenv/shims/python
(testenv) [mprat@europa] $ echo $PATH
/home/mprat/gems/bin:/home/mprat/.pyenv/plugins/pyenv-virtualenv/shims:/home/mprat/.pyenv/shims:/home/mprat/.pyenv/bin:/home/mprat/gems/bin:/home/mprat/.local/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
It is clear that the $PATH
variable that dictates which python version is running in my virtualenv was not sourced. Manually running source ~/.pyenv/versions/testenv/bin/activate
shows the output of echo $PATH
to be:
/home/mprat/.pyenv/versions/3.9.7/envs/tf/bin:/home/mprat/gems/bin:/home/mprat/.pyenv/plugins/pyenv-virtualenv/shims:/home/mprat/.pyenv/shims:/home/mprat/.pyenv/bin:/home/mprat/gems/bin:/home/mprat/.local/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
which means running which python
yields the expected result:
(testenv) [mprat@europa] $ which python
/home/mprat/.pyenv/versions/3.9.7/envs/testenv/bin/python
Why it is that pyenv activate XXXX
doesn't change the $PATH
variable (and seemingly doesn't run the appropriate activate
script)?
same problem for me.
I'm ok in real Ubuntu 20 but this happens in Windows subsystem Linux ( Ubuntu 20).
Had the same problem on macOS. This solved it for me - #390 (comment)
Please see updated and hopefully clearer Pyenv shell setup instructions in https://github.com/pyenv/pyenv#readme
eval "$(pyenv virtualenv-init -)"
should run in an rc file after eval "$(pyenv init -)"
as before.
I have got the same problem: https://stackoverflow.com/questions/69388462/pyenv-virtualenv-python-version-does-not-change-on-env-activation
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.