See first: pyenv docs
These instructions come from this intro to pyenv article, but this blog post also looks good.
Install dependencies:
brew install openssl readline sqlite3 xz zlibInstall pyenv:
curl https://pyenv.run | bashNote: the most recent instruction in the pyenv docs say you can just do this:
brew update
brew install pyenvThere will be a message in the console saying that you need to update your PATH. Be sure to read because the instructions seem to change as they update pyenv.
Basically, I have to add to my .bash_profile:
export PATH="$HOME/.pyenv/shims:$PATH"However, they have a longer, roundabout way of doing this:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"The reasons are explained in the pyenv docs.
Be sure to restart .bash_profile:
source ~/.bash_profileList all versions (warning: there's a lot):
pyenv install --listList specific versions:
pyenv install --list | grep " 3\.[678]"Install a version:
pyenv install -v 3.7.8Each version installed with pyenv is located in your pyenv root directory:
ls ~/.pyenv/versions/Check the versions you have first:
ls ~/.pyenv/versions/Then remove one like this:
rm -rf ~/.pyenv/versions/2.7.15or like this:
pyenv uninstall 2.7.15First check what you have:
pyenv versions
* system (set by /Users/jessicarush/.pyenv/version)
3.5.9
3.6.11
3.7.8
3.8.5The asterisk indicates which version is currently running. In the above output it's the system os version (2.7.16).
To switch you can use the global command:
pyenv global 3.7.8now check:
pyenv versions
system
3.5.9
3.6.11
* 3.7.8 (set by /Users/jessicarush/.pyenv/version)
3.8.5A great way to get peace of mind that the version of Python you just installed is working properly is to run the built-in test suite:
python -m testIf you ever want to go back to the system version:
pyenv global systemNote, you will need to update pyenv to see new python versions to install with pyenv install --list. To update pyenv:
pyenv updateNote that if you want to see which python, there will be a pyenv shim in place:
which python
/Users/jessicarush/.pyenv/shims/pythonTo see the actual path, you can run the following:
pyenv which python
/usr/bin/pythonTo see a complete list of pyenv commands:
pyenv commandsEach command has a --help flag that will give you more detailed information.
See also: pyenv commands reference