MacOS Python Path Issue – PyEnv Global Version Not Default

macospathpythonzsh

I have installed pyenv and used it to install Python 3.8.1 I had Python 3.7.6 installed manually before.

I have set 3.8.1 as global and, as this version is now markered with *, it was taken into account. However, which python3 and python3 -V are still outputting the values of 3.7.6! I have restarted the shell, but, unfortunately, the outputs are still the same.

Is this as expected behaviour? How to switch it to 3.8.1 properly?

NB echo $PATH outputs

/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin

enter image description here

enter image description here

Best Answer

https://github.com/pyenv/pyenv#basic-github-checkout

Define environment variable PYENV_ROOT to point to the path where pyenv repo is cloned and add $PYENV_ROOT/bin to your $PATH for access to the pyenv command-line utility.

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile

Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile.

-

Add pyenv init to your shell to enable shims and autocompletion. Please make sure eval "$(pyenv init -)" is placed toward the end of the shell configuration file since it manipulates PATH during the initialization.

$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

Restart Shell

exec "$SHELL"