Manage multiple versions of Python with pyenv


As of writing, macOS Catalina ships with Python 2.7.2 and Python 3.7.6, the latest version of Anaconda runs at Python 3.7.6 and the latest stable release of Python on python.org is 3.8.4. Meanwhile, HomeBrew is offering 3.8.3 and a beta of 3.9 and 3.10; as well as several versions of Anaconda.

So, what should you install?

In short, pyenv, a utility that lets you easily switch between and install multiple versions of Python.

Install pyenv

Install XCode command line tools

xcode-select --install

Install Homebrew

copy the installation command from brew.sh

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Install pyenv

brew install pyenv

Install python

list available versions to install

pyenv install --list

install the version you require

pyenv install 3.8.3

Edit your .zprofile

Add the following lines to your .zprofile

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

This script initialises pyenv

Re-run your .zprofile

. ./.zprofile

Now test your python installation

which python
# /Users/johndunning/.pyenv/shims/python
python --version
# Python 3.8.3
pip --version
# pip 19.2.3 from /Users/johndunning/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pip (python 3.8)

Going forward

use pyenv to manage your python and anaconda installations

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Up ↑

%d bloggers like this: