Skip to content

Instantly share code, notes, and snippets.

@samuelbradshaw
Last active April 20, 2022 01:32
Show Gist options
  • Save samuelbradshaw/932d48ef1eff07e288e25e4355dbce5d to your computer and use it in GitHub Desktop.
Save samuelbradshaw/932d48ef1eff07e288e25e4355dbce5d to your computer and use it in GitHub Desktop.
Installing Python 2 and 3 on macOS

Installing Python 2 and 3 on macOS

Starting with macOS 12.3, Python is no longer bundled with macOS. These instructions allow you to set up Python 2 and Python 3 side-by-side using pyenv. The instructions were tested on an Apple Silicon Mac, but the process on an Intel Mac should be similar.

Install Homebrew

Homebrew is a popular package manager that makes it easy to install command line tools. If you don’t yet have Homebrew installed, instructions can be found here: https://brew.sh

Verify that Homebrew is installed:

brew -v

Install pyenv

  1. Run the Homebrew install script for pyenv:
brew install pyenv
  1. Update your .zprofile and .zshrc files to reference pyenv:
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
  1. Install the latest available Python 2 and Python 3 versions:
LATEST_PYTHON_2=$(pyenv install --list | grep -e "^\s*2[0-9.]*[0-9]\s*$" | tail -1 | xargs)
LATEST_PYTHON_3=$(pyenv install --list | grep -e "^\s*3[0-9.]*[0-9]\s*$" | tail -1 | xargs)
pyenv install $LATEST_PYTHON_2
pyenv install $LATEST_PYTHON_3
pyenv versions
  1. Tell pyenv to activate the two versions of Python that were installed:
pyenv global $LATEST_PYTHON_2 $LATEST_PYTHON_3
pyenv versions
  1. Open a new terminal window.

  2. Verify that the pyenv version of Python 2 is loaded:

which python
python -V
  1. Verify that the pyenv version of Python 3 is loaded:
which python3
python3 -V
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment