Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyenv does not use correct python version

using pyenv 2.0.3

when i'm in a folder with a python-version file, the python keeps using the system version which is 2.7.6. (not sure why it is 2.7.6 since i install 3.9.7 via brew).

$ python -V
Python 2.7.16

looking via pyenv gives

$ pyenv which python
/Users/jaco/.pyenv/versions/trading/bin/python

Activating it already says it is activated.

i have

# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

in my zshrc

also don't seem to have the bin folder of pyenv? is this new on the v2?

$ l /Users/jaco/.pyenv/bin
ls: /Users/jaco/.pyenv/bin: No such file or directory

Also setting pyenv global 3.9.1 does not work, it keeps 2.7

like image 965
Tjorriemorrie Avatar asked May 07 '26 06:05

Tjorriemorrie


2 Answers

The answer is to put the shims on the path

# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
#if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
like image 179
Tjorriemorrie Avatar answered May 08 '26 20:05

Tjorriemorrie


Assuming you're running MacOS and have installed pyenv via Homebrew, you'll need to do the following:

# Adjust the session-wide environment for your account.
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile

# Enable autocompletion and all subcommands
echo 'eval "$(pyenv init -)"' >> ~/.zshrc

From pyenv installation docs:

MacOS note: If you installed Pyenv with Homebrew, you don't need to add the PYENV_ROOT= and PATH= lines. You also don't need to add commands into ~/.profile if your shell doesn't use it.

like image 23
j4ckofalltrades Avatar answered May 08 '26 20:05

j4ckofalltrades



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!