macOS 11 comes with a default version of python2, which is now obsolete in favor of python3. Python2 reached end of life in January 2020.
$ type -a python python is /usr/bin/python $ which python /usr/bin/python $ python --version Python 2.7.16
We are certainly do not want to touch macOS's default python2 and will leave it as it is. Let's install
pyenv to manage multiple versions of Python.
There are two ways to install
pyenv on macOS:
- Via Homebrew: this is the quickest way. Unfortunately I could not make
pyenvworks as expected on a fresh macOS 11 (Apple Silicon).
- Git checkout:
pyenvteam has documented the install process in details here. However, when I followed that step by step and applied on my new macOS 11 (M1), it did not work. After serveral hours tweaking, here's how I managed to get the
pyenvto work with Git check out installation.
pyenv repo into your home folder:
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv $ cd ~/.pyenv && src/configure && make -C src
.zshrc and add the following lines at the bottom of the file (macOS 11 comes with zsh as the default shell)
export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv init -)"
3.Quit your terminal and reopen it. Now
pyenv should be activated and you can start to install some Python.
$ arch arm64 $ which brew /opt/homebrew/bin/brew $ brew --version Homebrew 3.1.11 Homebrew/homebrew-core (git revision 7c34424687; last commit 2021-06-10) Homebrew/homebrew-cask (git revision ab9a64f927; last commit 2021-06-10) $ pyenv --version pyenv 2.0.1-3-g1706436f
pyenv suggests that before install any version of Python, we need a Python build environment for Mac. Make sure you have Xcode Command Line Tools (
xcode-select --install) and Homebrew on your system. Then:
$ brew install openssl readline sqlite3 xz zlib
For a complete guide on how to install Homebrew on a fresh macOS 11 Big Sur (Apple Silicon), check out this guide.
$ pyenv install 3.9.4 python-build: use firstname.lastname@example.org from homebrew python-build: use readline from homebrew Downloading Python-3.9.4.tar.xz... -> https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tar.xz Installing Python-3.9.4... python-build: use readline from homebrew python-build: use zlib from xcode sdk Installed Python-3.9.4 to /Users/squademy/.pyenv/versions/3.9.4
pyenv install Python 3.9.4 seamlessly on Mac M1 and everything works out of the box.
This guide originally published and frequently updated here