Python Version Management with Pyenv on macOS

Pyenv can make managing multiple versions of python a lot easier. Pyenv allows you to easily select, install and compile specific versions of python for testing and development.

Setting up PyEnv

Using Brew

brew update
brew install pyenv

Install the dependencies requires to build Python. This includes the Xcode Command Line Tools and a few libraries.

xcode-select --install
brew install openssl readline sqlite3 xz zlib

Then add Pyenv to your path (In this case .zshrc):

export PYENV_ROOT="$HOME/.pyenv"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
export PATH="$PYENV_ROOT/bin:$PATH"

Installing a Python version

Install the Python version of your choice. These are installed to $(pyenv root)/versions

pyenv install <version number>

To see what versions are available:

pyenv install --list