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.
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.
nano ~/.zshrc
alias python=/usr/local/bin/python3
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.
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!