2

I installed pyenv on mac and have used the following commands to install the required python version:

pyenv install 3.8.0
pyenv global 3.8.0

I am using zsh and my zshrc file contains the following:

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

When I check the python version, I can still see the old system version i.e. 2.7.15 responded by the command:

python -V

Any thoughts on what I might be doing wrong?

I have tried bash as well. I did not see any pyenv references in my bashrc file.

3 Answers 3

6

Does it work if you restart your shell?

$ exec "$SHELL"

If yes then the problem is that zshenv is loaded too soon, you can add the following to .zprofile or .zshrc

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi
Sign up to request clarification or add additional context in comments.

1 Comment

Just by running eval "$(pyenv init -)" on the same shell should also fix the problem. New shells should also follow the global setting. Thanks @ddayan!
1

I've run into this same situation with my system version on Mac not updating after running the pyenv commands. This is what worked for me (you need to reset your shell and pyenv after setting the command):

pyenv global 3.7.4
eval "$(pyenv init -)"

Comments

1

Following the github documentation of pyenv, there are some specifics for each shell.

https://github.com/pyenv/pyenv?tab=readme-ov-file#b-set-up-your-shell-environment-for-pyenv

For example for zsh users, the documentation states to add those lines to your .zshrc

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - zsh)"

See the little difference in the last sentence, zsh statement after the init -

eval "$(pyenv init - zsh)"

Of course the SHELL has to be fully restarted after that :

exec "$SHELL"

or simply restart the (i)Term(2|inal)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.