Python is a versatile and powerful programming language with widespread applications. As a Mac user, you may be interested in installing and running Python on your device to run certain applications or to begin creating and running your own Python scripts.
While an older version of Python does come preinstalled with some versions of macOS, you’ll probably need to install a newer version. To help you, we’ll explain how to install and run Python on your Mac below.
Do I Need to Install Python on macOS?
As a Mac user, you might wonder if you need to install Python on your system. The answer is probably yes—for two important reasons.
The first reason is compatibility. If you’re running macOS Monterey 12.2 or earlier, you probably have Python 2.7 pre-installed. However, Python 3 is the latest version and has significantly improved features compared to Python 2.7. Python 2.7 is also old, no longer officially supported, and less secure than Python 3.
The second reason is much simpler—Python might not be installed at all. If you’re running macOS Monterey 12.3 or later, you’ll find that Apple has removed Python 2.7 from the installation completely. You’ll need to install Python again to continue.
To check the Python version on your Mac, open the Terminal application and type python –version. If it doesn’t run, or it lists 2.7 as the version, you should consider upgrading to a newer Python release.
You can use Python’s official installer, found on their website, or use a package manager like Homebrew to install the latest version of Python. To check if Python 3 is already installed, type python3 –version in the Terminal instead.
How to Install Python on macOS Using the Official Installer
The quickest way to install Python on macOS (whether the older 2.7 release or the newer Python 3 release) is to use the official installer from the Python website. To install Python this way, follow these steps.
- Start by opening your web browser and visiting the Python download page. The website will automatically detect your operating system and display a download button which you can press to download the latest version of the Python installer for your Mac. If it doesn’t, click the macOS link and choose the latest Python release.
- After downloading the installer package, open Finder, locate it in your downloads folder and double-click the file to begin the installation process.
- Press Continue and follow the on-screen instructions to configure and install Python. You can choose between the default installation settings or customize them according to your preferences.
- The installation process may take a few minutes. Once complete, you can verify the installation by opening the Terminal application on your Mac and running the python –version or python3 –version commands. The Terminal should show the correct version number of your Python installation.
- To run Python, type python or python3 in the Terminal and press enter. This will allow you to type Python code directly into the Python terminal.
- To exit, type exit() and press enter.
At this point, you’ve successfully installed Python on your Mac. You can now run your own Python scripts or applications or create your own. If you want, you can also install additional Python packages using the Python PIP installer.
How to Install Python on macOS Using Homebrew
An alternative method for installing Python on a Mac is to use Homebrew. Homebrew is a third-party package manager for macOS that allows you to quickly install applications using the terminal, replicating a Linux-style experience for your Mac.
Ironically, Homebrew requires Python to be installed to work correctly, so installing Homebrew should ensure that a working Python installation is available, too.
To install Python on your Mac using Homebrew, follow these steps.
- First, open your Terminal application and check if Homebrew is already installed by running this command: brew –version. If Homebrew is already installed, you’ll see its version number. If not, continue to the next step.
- To install Homebrew, run this command in the Terminal: /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)”. The script will explain what changes it will make and prompt you to approve them before the installation begins.
- After Homebrew is installed, you can use it to install Python. To do this, type brew install python (or brew install python3) into the Terminal and press the enter key. This will install the latest version of Python available.
- Afterward, run brew link python (or brew link python@3.XX (replacing XX with the correct version number) and restart the Terminal app to ensure the application works correctly.
- Once Python is installed, you can check the version by running the python –version command in the Terminal (or python3 –version instead). This will show the installed version of Python 3.
- To run Python, type python or python3 from the Terminal to launch the Python terminal. The version number will appear after the command runs to allow you to identify which version you’re loading.
- Type exit() and press enter to exit at any point.
At this point, Python should be installed correctly, and you can begin to use it. Remember to keep your Homebrew and Python installations up-to-date by periodically running brew update and upgrade from the Terminal app.
Programming With Python on a Mac
Installing and running Python on your Mac is straightforward using the steps above. While older macOS releases might have Python 2.7 installed, installing a newer Python 3 release on your Mac is better.
If you run into any problems running your own third-party apps, don’t forget to allow your Mac to run unverified apps next.