Making Python 3 Default in MacOS
Python users on the Mac are likely aware that Python is being deprecated from macOS 12.3 onward, and will no longer be preinstalled on the Mac. But Python remains an incredibly popular programming language, and if you rely on Python you’ll likely want to continue to have Python available in macOS. It’s easy to get Python 3 on the Mac, so let’s go a step further and show you how you can make Python 3 the new default Python version in macOS, whenever the python command is executed.
Installing Python 3 on the Mac
If you haven’t installed Python 3 yet it’s easy to do so with a single homebrew command:
brew install python
This will install the latest Python 3 release available through HomeBrew. Again, you can also install it using the Python 3 installer, or even the MacAdmins Python release if you’d prefer.
How to Make Python 3 the Default in MacOS
- From the Terminal, open zshrc in your text editor of choice, we’ll use nano for the sake of ease:
- Add the following alias at the bottom of the .zshrc file:
- Hit Control-O and then Control-X to save the edit and then exit out of nano
Now you can confirm the alias worked by checking the python version:
$ python --version
This should be the same response as if you type, since the python command has been aliased to python3:
Remember this is only an alias. If you continue to have the original Python 2.7.x release installed on the Mac, it remains accessible and usable by specifying the full path, like so:
Keep in mind that in future versions of MacOS, Python 2.x will no longer be bundled.
We’re using aliases here in this example, but you can use a symbolic link linking /usr/bin/python3 to /usr/bin/python instead if you’d prefer to go that route.
What happened to Python in MacOS?
For those who aren’t aware, Apple has been warning for a while now that Python would be deprecated from future macOS versions, and that time has finally arrived with macOS Monterey 12.3 onward. This is found in the developer notes, listed under Deprecations:
Python 2.7 was removed from macOS in this update. Developers should use Python 3 or an alternative language instead. (39795874)
Thus if you are or were dependent on Python 2.7.x for any particular reason, you’ll either need to update your programs for Python 3 compatibility, maintain an older deprecated Python 2.x release (which is possible with Homebrew, etc), or rewrite everything and move on to another language entirely.
If you have any relevant thoughts, information, or experiences with Python in the latest macOS versions, share in the comments.