MAC

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 probably 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.

  1. From the Terminal, open zshrc in your text editor of choice, we’ll use nano for the sake of ease:
  2. nano ~/.zshrc

  3. Add the following alias at the bottom of the .zshrc file:
  4. alias python=/usr/local/bin/python3

  5. 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
Python 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 warned 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.





Source link

Naveen Kumar

Friendly communicator. Music maven. Explorer. Pop culture trailblazer. Social media practitioner.

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button