How to update Python on Mac: The quickest methods
I remember when my friend, a talented software developer, was stuck on a project for weeks. He was grappling with a stubborn bug that seemed impossible to fix. After countless hours of debugging, he finally got the code to run — but not without frustration. It turned out that a feature to address his issue had been added to Python ages ago, and all he needed was to update the version. Watching him struggle made me realize the importance of staying up-to-date with software. If you're in a similar boat, let's dive into how to update Python on your Mac and avoid unnecessary headaches.
Why should you update Python on Mac?
You don't have to upgrade to the shiniest version every time, but you also don't want to be too far behind. Technical debt is easy to accumulate, and in my experience, every new version is better than the last. Also, with every skipped version, updating to the latest one is harder.
Three key reasons to keep Python updated:
- Security: Outdated software gets vulnerable. Updates patch security holes, keeping your Python code safe.
- New features: Every update usually comes with new tools and libraries for better productivity.
- Compatibility: Keeping Python current ensures it plays nicely with your Mac and other software.
How to check current Python version in Terminal
Depending on your macOS version, your device may be pre-installed with Python 2.7. Here's how to check the Python version on Mac :
- Go to Applications > Utilities > Terminal.
- In the Terminal window, type python3 --version or type python --version to check for Python 2 (if still installed)and press the Return key.
- Read the output: If Python 3 is installed, you'll see output like Python 3.x.x (where x.x represents the specific version numbers). If you see Python 2.x.x, it means the default Python on your system is still version 2.
Method 1: Update Python via the official Python website
Updating Python through its official website is a straightforward method, especially for beginners. Here's how to do it:
- Open your web browser and go to python.org.
- Click Downloads in the main menu. The site should detect you're on macOS and offer the latest stable version of Python. Click the download button.
- Once the .pkg installer file is downloaded, open it.
- Accept the license agreement and follow the on-screen instructions to complete the installation.
- After the installation is complete, open Terminal and type python3 --version to check the Python version.
Method 2: Update Python using Terminal
This method is ideal if you want more control over the installation and configuration of Python on your Mac. It requires a package manager.
I'll show you how to update Python in Terminal with Homebrew:
- Open Terminal > Install Homebrew. If you don't have Homebrew installed yet, type /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" in Terminal.
- Type brew update and press the Return key to check that the Homebrew is up to date.
- Type brew upgrade python and press the Return key to update Python to the latest version.
- Type python3 --version to verify the Python update.
This should return the version number of the latest installed version.
Tip: I recently came across this tool called CodeRunner that I think many would really like, especially those who use Python a lot more than I do. It's super fast and lets you write, run, and debug code easily, which seems handy. It also supports over 25 languages, so it's not just for Python. I tried it out briefly, and what stood out to me was the clean, modern interface and how easily it handles different coding tasks. Might be worth checking out if you're looking for a smoother workflow.
How to set the new Python version as default
After updating to the latest version of Python, you'll want to set it as the default version on your Mac. This ensures your system uses the latest version for all Python commands and avoids compatibility issues with scripts and packages. Here’s how to do it:
Here's how to do it:
- Open Terminal and type which python3 to find the installation path of your new Python.
- Edit your shell profile (a hidden file in your home directory that stores configuration settings for your Terminal).
- For macOS Catalina and later, type nano ~/.zshrc; for older macOS versions, type nano ~/.bashrc and press the Return key.
- In the shell profile file (either .bashrc or .zshrc), type export PATH="/path/to/new/python:$PATH" at the top to set the new Python version as the default.
- Replace /path/to/new/python with the path you got from the previous step (e.g., /usr/local/bin/python3).
- Press control + O > Return key to save the file. Then press control + X to exit.
- For applying the updated settings, type source ~/.bashrc for Bash; type source ~/.zshrc for Zsh.
- Finally, confirm that the new Python version is now the default. Type python3 --version or python --version accordingly.
Note that macOS still includes Python 2 by default, so always use python3 when referring to Python 3 versions to avoid conflicts.
Troubleshooting Python update issues
As with everything involving programming languages, you’re bound to run into an error code at some point. These are some problems you can encounter and how to troubleshoot them:
Permission denied errors
You may run into multiple permission errors during installation or upgrade. You can bypass this by adding the sudo before a command in Terminal. This gives the command elevated privileges and allows it to run as an administrator. For example:
This will preclude any potential permission errors. You may need to enter your password to proceed.
Path issues
This happens when the old version still shows as default when you check. To troubleshoot, make sure your path is set correctly in .bash_profile or .zshrc and that you've sourced the file to apply changes.
Version conflicts:
Multiple Python versions can cause command conflicts, leading to unexpected behavior. You can check which versions are installed typing ls -l /usr/local/bin/python*. Then, remove older versions or ensure the correct one is linked.
Outdated pip
Outdated pip can occur after a Python update because pip (the Python package installer) is installed separately for each Python version. If the pip version doesn't match the newly updated Python, you may encounter issues with installing or managing packages. To upgrade pip for the new Python version, type python3 -m pip install --upgrade pip.
Unrecognizable packages
The issue can occur after a Python update because packages installed for an older version of Python may not automatically carry over to the new version. In such cases, you may need to reinstall the packages for the updated Python version. To troubleshoot, type pip list > if necessary, reinstall packages for the new Python version and, type python3 -m pip install package-name.
Upgrade Python on Mac with no hassle
New versions of Python come with speed upgrades, better error messages, and tighter security. If you need to update Python Mac or otherwise, you can do it either through the website or Terminal. They both work perfectly and will set you on your way to your Python development.
Along the way, you can gain an edge with DevUtils, where you get one-click access to a huge set of useful and intuitive development utilities that all work offline. While you master Python programming, SnippetsLabs can help collect, organize, and share your code snippets across multiple languages. If you need a lightning-fast code editor, CodeRunner can write, run, and debug quickly from a single app with extensive support for more than 25 languages.
All of these apps, along with dozens of other tools for macOS and iOS, are available on Setapp. The seven-day trial gives you a free test run and access to a platform of high-performance, best-in-class macOS and iOS apps.
FAQ
How to install the latest Python version?
Visit python.org, download the latest macOS installer, and run it. Alternatively, use Homebrew in Terminal. Open Terminal and type the following commands: brew update
(updates Homebrew), brew install python
(installs the latest Python version).
How to check the Python version in Mac Terminal?
To check the Python version on Mac, open Terminal and type python3 --version
or python --version
for Python 2. To see all installed versions, type ls /usr/local/bin/python*
.
How to choose the Python version in Terminal?
To choose a specific Python version in Terminal, use a version manager like pyenv and run pyenv global <version>
to set your desired default version.