This guide introduces two common ways to update Python Mac. Each of them comes with detailed instructions and how they are compared to each other.
There are two main ways to update Python on Mac: Homebrew and .pkg files. Check them out below to see which option suits you the best.
Update Python On Mac
Homebrew is a popular application on macOS. It offers many functionalities and an experience similar to those of Linux package managers. This is an area where macOS has always lagged behind Linux distributions for advanced users. Homebrew comes in and fills the void.
Its biggest distinction is the powerful command line interface. Casual macOS users may find this complicated and counterintuitive. While it is true that this demands a steeper learning curve, this interface comes with many big advantages.
As a Python developer, you are likely to learn to use a terminal anyway. This way, you can install, upgrade, or remove packages with just a single command. You can even incorporate Homebrew into your script to accomplish more complicated tasks.
Open Terminal on your Mac computer (you can also use your favorite terminal emulator. If you haven’t installed homebrew, paste and run this command:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
It will fetch the official installer script provided by Homebrew. It will explain what it will do at each step and ask for your permission before installing Homebrew into your macOS system.
Then you can upgrade the package python:
brew update && brew upgrade python
The command above fetches the latest definitions of packages (formulae) supported by Homebrew, then performs an upgrade to your Python installation. It may prompt you for permission, and the process can take a minute or two.
From now on, repeat the command now on if you want to upgrade Python without having to install Homebrew again. You can use this command regularly to check for new versions of every package managed by Homebrew and upgrade it:
brew update && brew upgrade
This method will make sure all the packages on your system are up-to-date with minimal effort since you don’t have to manually check for each application.
Some important notes:
- Homebrew only supports Python 3.x. Its Python 2 formula was removed in 2019 due to the deprecation of this older version. Consult the second method below if you want to update Python 2.
- The Python installation provided by Homebrew comes with pip – the recommended package installer for this programming language. Setuptools is also installed with Homebrew’s Python formulas. You can upgrade them separately through pip without installing a new Python version:
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade setuptools
- The executables python3 and pip3 in your macOS system will point to those of Homebrew installation. If you want to locate their unversioned symlinks or of other executables like python-config, use this command:
With .pkg Files
In addition to using Homebrew, you can upgrade Python through its official installer. The project provides installers of various formats for all major platforms, including macOS.
- Go to Python’s download page for macOS. Click the version (Python 3 or Python 2) you want to upgrade.
- Scroll down and find the .pkg installer for macOS. Click it to download and wait for a few seconds.
- Open the file explorer and open the .pkg file on your download folder. Follow the installer’s instructions to upgrade your Python installation.
This is a fast and convenient way to upgrade Python if you aren’t familiar with the command line. However, you will need to manually find out whether Python has a new version and repeat this step again to upgrade it. Compared to automatic management tools like Homebrew, you can easily miss new versions of applications like Python.
You can use Homebrew (our recommendation) or the official .pkg installer to update Python on Mac. Each method has its own advantages, but both of them can make sure your Python installation can always be up-to-date.