pyenv / pyenv-virtualenv

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

pyenv dos not work #400

Closed MonkeyInWind closed 3 years ago

MonkeyInWind commented 3 years ago
➜  Public pyenv versions
* system (set by /home/pi/.pyenv/version)
  3.9.6
➜  Public pyenv virtualenv 3.9.6 py396
Looking in links: /tmp/tmph3f6ru1q
Requirement already satisfied: setuptools in /home/pi/.pyenv/versions/3.9.6/envs/py396/lib/python3.9/site-packages (56.0.0)
Requirement already satisfied: pip in /home/pi/.pyenv/versions/3.9.6/envs/py396/lib/python3.9/site-packages (21.1.3)
➜  Public pyenv versions
* system (set by /home/pi/.pyenv/version)
  3.9.6
  3.9.6/envs/py396
  py396
➜  Public python --version
Python 2.7.16
➜  Public pyenv activate py396
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(py396) ➜  Public pyenv --version
pyenv 2.0.4
(py396) ➜  Public python --version
Python 2.7.16
(py396) ➜  Public python3 --version
Python 3.7.3
(py396) ➜  Public pyenv deactivate
➜  Public python --version
Python 2.7.16

.zshrc

export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
changtingQ commented 3 years ago

i also find the issue, i can't slove it.

unoxxis commented 3 years ago

I had that too and it is related to zsh's behaviour. You need to rehash after you activate a virtual environment in zsh. See https://github.com/pyenv/pyenv/issues/31#issuecomment-20947029

If you want to rehash automatically in zsh, either use zstyle ':completion:*' rehash true in your .zshrc (see https://github.com/ohmyzsh/ohmyzsh/issues/3440) or include a shell function for pyenv in your zshrc that passes all arguments to pyenv and afterwards calls rehash (see top answer in https://stackoverflow.com/questions/34340575/zsh-alias-with-parameter).

MonkeyInWind commented 3 years ago

I had that too and it is related to zsh's behaviour. You need to rehash after you activate a virtual environment in zsh. See pyenv/pyenv#31 (comment)

If you want to rehash automatically in zsh, either use zstyle ':completion:*' rehash true in your .zshrc (see ohmyzsh/ohmyzsh#3440) or include a shell function for pyenv in your zshrc that passes all arguments to pyenv and afterwards calls rehash (see top answer in https://stackoverflow.com/questions/34340575/zsh-alias-with-parameter).

Thanks