This tutorial will show you how to install Python3 on a macOS system. To demonstrate the installation process, I will present the steps on macOS Catalina (Version 10.15). Instead of installing Python3 via the installer from the Python website, this tutorial will use brew
which is the most popular Package Manager for macOS.
Installing brew on your system is straightforward, you just need to copy-and-paste the following command to the Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
We first install Python3 via brew
command, and then we define location of the bin
directory of the newly installed Python3 to notify the system to know where to look for the installed Python packages.
Install Python3 via brew:
brew install python3
Update the zsh profile by creating a new ~/.zshrc
, or open the current one:
nano ~/.zshrc
Insert the following lines of code into the first line of ~/.zshrc
:
# Configure PATH for Python 3
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
To make sure that you have correctly installed the Python3 to the system, you need to restart the Terminal (quit and re-open the Terminal), and then execute the following commands:
which python3
(Expected output: /usr/local/bin/python3)
python --version
(Expected output: Python 3.9.10)
- If you get this error message
Failed during: /usr/local/bin/brew update --force --quiet
when installing Homebrew on macOS, you should execute the following command withsudo
level:sudo chown -R $(whoami) $(brew --prefix)/*