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.
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
- Run the Homebrew install script for pyenv:
brew install pyenv
- Update your .zprofile and .zshrc files to reference pyenv:
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
- 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
- Tell pyenv to activate the two versions of Python that were installed:
pyenv global $LATEST_PYTHON_2 $LATEST_PYTHON_3
pyenv versions
-
Open a new terminal window.
-
Verify that the pyenv version of Python 2 is loaded:
which python
python -V
- Verify that the pyenv version of Python 3 is loaded:
which python3
python3 -V