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 already installed Python 3 on the Mac using the official Python installer from here or Homebrew, you can skip this section.
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
We are assuming you’re using the default Zsh shell (or Oh My Zsh) and thus modifying .zshrc, but if you still use bash then you’d add the alias into .bashrc instead.
From the Terminal, open zshrc in your text editor of choice, we’ll use nano for the sake of ease:
nano ~/.zshrc
Add the following alias at the bottom of the .zshrc file:
alias python=/usr/local/bin/python3
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 --versionPython 3.9.8
This should be the same response as if you type, since the python command has been aliased to python3:
python3 --version
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:
/usr/bin/python
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:
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.
The above is the detailed content of Making Python 3 Default in MacOS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

You’ve had your Mac for a few years, and you’re starting to feel the effects of your device aging—the battery doesn’t hold up as well as it used to. To avoid getting stuck with a dead Mac, you have no choice but to take your charger e

The Focus Modes functionality comes with several pre-set options such as Work, Driving, Sleep, and users are also free to create custom ones for any scenario imaginable. Should you find yourself not needing a multitude of Focus modes—whether because

If you trust Siri to accurately transcribe your speech into text and send it as a message, you can activate a setting that lets Siri send messages automatically from your iPhone without asking for confirmation first.With the confirmation feature enab

Some users of Mac computers running MacOS Sierra and MacOS High Sierra have reported issues when trying to log in to an Apple ID or iCloud via System Preferences, as well as problems accessing iCloud.com using Safari. In addition, Safari fails to loa

Have you ever received a long audio message on your iPhone and while listening, the screen turns off, interrupting the playback and forcing you to start over? It's pretty frustrating, isn't it?Next time you receive a lengthy voice message on your iPh

iOS 16 is now available for iPhone users, offering a solid update packed with practical features you're sure to enjoy.The most noticeable and exciting addition is the ability to personalize your lock screen. However, there are also plenty of smaller

In this blog post, we’ve gathered the 22 most significant breaches that happened back in 2017. All of the reports were conducted by Chris Vickery — a data breach hunter, who had partnered with MacKeeper to provide repor

Customizing your Mac by renaming it helps set it apart from other devices, especially when using AirDrop, and makes it easier to identify on a network.In macOS Ventura 13 and later versions, the method for changing the computer name has changed compa
