Something about Pyenv On MacOS
#Via homebrew
brew update
brew install pyenv
If you using Bash
, and adding the following lines to the end of ~/.bash_profile
export PATH="$HOME/.pyenv/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
Then source the file to call the exports
source ~/.bash_profile
If you using ZSH
with oh-my-zsh, adding the pyenv plugin to the plugins array in ~/.zshrc.
plugins=(
pyenv
)
Then source to activate the changes.
source ~/.zshrc
#Check pyenv version
pyenv --version
#Check commands
pyenv --help
#List all available version of python
pyenv install -l
#Install the latest stable version
pyenv install 3.8.5
#List all version was installed
pyenv versions
* system
2.7.18 (set by /Users/stana/.pyenv/version)
3.7.8
3.8.5
#Setting 3.7.8 as the default interpreter
pyenv global 3.7.8
#And verify the version we are using
python --version
The special version string system
will use
your default system Python. Run pyenv versions
for a list of
available Python versions.
Example: To enable the python2.7 and python3.7 shims to find their respective executables you could set both versions with:
pyenv global 2.7.18 3.7.8
#And verify the version we are using
python --version
#Python 2.7.18
python3 --version
#Python 3.8.5
The usage of these three commands(pyenv shell | local | global) is a bit similar, here is one of them for illustration.
# Display version
pyenv local
# Setting version
pyenv local 2.7.18 3.7.8
# Unset version
pyenv local --unset