Home  >  Article  >  Make Python 3 the default interpreter on MacOS

Make Python 3 the default interpreter on MacOS

王林
王林forward
2023-05-07 15:34:071364browse

Installing Python 3 on Mac

You can skip this section if you have already installed Python 3 on your Mac using the official Python installer here or Homebrew.

If you don't have Python 3 installed, it's easy to do using a homebrew command:

brew install python

This will install the Python 3 available through HomeBrew Get the latest Python 3 version. Likewise, you can install it using the Python 3 installer, or even the MacAdmins Python version if you prefer.

How to make Python 3 the default in MacOS

We assume you are using the default Zsh shell (or Oh My Zsh) and modify .zshrc accordingly, but if you are still using bash, Then you should add the alias to .bashrc.

    1. From the terminal, open zshrc in the text editor of your choice, for convenience we will use nano:

nano ~/.zshrc

    1. Add the following alias at the bottom of the .zshrc file:

alias python=/usr/local/bin/python3

  1. Press Control-O, then Control-X to save your edits and exit nano

Now you can confirm that the alias is valid by checking the python version:

$ python --version<br>Python 3.9.8

This should The same response as when you typed it, because the python command was aliased to python3:

python3 --version

Remember, this is just an alias. If you continue to install the original Python 2.7.x version on your Mac, you can access and use it by specifying the full path, like this:

/usr/bin/python

Please remember that Python 2.x will no longer be bundled in a future version of MacOS.

We used aliases in this example, but if you prefer to go this route, you can use a symlink that links /usr/bin/python3 to /usr/bin/python.

What happened to Python in MacOS?

For those who don’t know, Apple has been warning for some time that Python will be deprecated in future macOS versions, and that time has finally arrived with the arrival of macOS Monterey 12.3. This can be found in the developer notes, listed under Deprecations:

Deprecation
Python 2.7 has been removed from macOS in this update. Developers should use Python 3 or an alternative language. (39795874)

So if you depend or have relied on Python 2.7.x for any specific reason, you either need to update your program for Python 3 compatibility or maintain the old deprecated Python 2.x version (this could use Homebrew etc.), or rewrite everything and move to another language entirely.

The above is the detailed content of Make Python 3 the default interpreter on MacOS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yundongfang.com. If there is any infringement, please contact admin@php.cn delete