Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having trouble switching python versions using pyenv global command

I have installed pyenv on Mac using homebrew and downloaded the version of Python 3.7.9. Everything works except when I use pyenv global 3.7.9, python3 -V still gives me version 3.9.7. How do I fix this?

like image 798
Paul Avatar asked Jun 15 '26 11:06

Paul


2 Answers

Run the commands below in your terminal before running pyenv install <VERSION> / pyenv global <VERSION> / python --version

eval "$(command pyenv init -)"
eval "$(command pyenv init --path)"

You may need to re-install your required python version

To avoid running these commands in every session, add the commands to your shell profile file ~/.zshrc or ~/.bashrc

Entire .zshrc that works as of March 2022:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
export PIPENV_PYTHON="$PYENV_ROOT/shims/python"

plugin=(
  pyenv
)

eval "$(pyenv init -)"
eval "$(command pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
like image 191
Eladio Avatar answered Jun 17 '26 00:06

Eladio


For Arch Linux, these worked, as similarly answered by @Eladio:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
export PIPENV_PYTHON="$PYENV_ROOT/shims/python"
pyenv init -
command pyenv init --path
like image 22
kaiya Avatar answered Jun 17 '26 02:06

kaiya