Install pyenv with Homebrew on macOS:
brew update
brew install pyenv
Define your vitual env variables:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
Restart your shell so the path changes take effect
exec "$SHELL"
Check the available python versions:
pyenv install --list
Install the required python version:
pyenv install 3.9
Set it as your global version:
pyenv global 3.9