Skip to content

Instantly share code, notes, and snippets.

@samuelbradshaw
Last active April 27, 2025 21:50
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
@ettingshausen
Copy link

error while execute pyenv install $LATEST_PYTHON_2

~ pyenv install $LATEST_PYTHON_2
Error: No available formula with the name "[email protected]". Did you mean [email protected], [email protected] or openssl@3?
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-2.7.18.tar.xz...
-> https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tar.xz

@samuelbradshaw
Copy link
Author

samuelbradshaw commented Oct 31, 2024

It looks like it's failing while trying to install the openssl dependency.
Are you running a recent version of pyenv? You could try brew upgrade pyenv.
You can also try installing openssl manually – that may allow the pyenv Python installer to skip the failing step: brew install openssl

@ettingshausen
Copy link

This issue doesn't seem to affect. In the end, it was successfully installed.

@iceyfire1404
Copy link

iceyfire1404 commented Mar 24, 2025

I got the same issue. I think this is because python2 is not supported by arm systems. I am using apple silicon

@flyingrx
Copy link

It works on my mac mini M4. Thanks.

@thomergil
Copy link

This worked for me:

PYTHON_CONFIGURE_OPTS="--disable-toolbox-glue" pyenv install 2.7.18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment