On macOS Ventura & Sonoma on Apple Silicon
To install homebrew's version of python3:
brew install python3
This installs brew's version of python3.x but does not override the the link to macOS's version of python3 when you use the
python3 command. You can confirm which python3 is being used with the
which python3 command. Now, you have two primary options here:
- You can unlink the system default's python3 and relink python3 to the homebrew version (see kraspa11's answer)
- You can simply add an alias for python3 in your
~/.zshrc file which can point to brew's version instead (I prefer this because it results in fewer edits to system defaults).
If you prefer option #2:
nano ~/.zshrc or your desired editor. BTW, if you want to see "hidden" files/folders in your /Users/[username] folder where
.zshrc resides, open your user folder in finder and press ⇧ Shift + ⌘ Command + . (period). This will show/hide all hidden files and folders in your Finder.
At the end of the
.zshrc file, add the following lines:
# ensure "python3" command uses homebrew's version of python3
# OPTIONAL: ensure "python" command uses homebrew's version of python3
/opt/homebrew/bin/python3 instead of
/opt/homebrew/opt/[email protected] so if/when you update your version from 3.11 to 3.12 and so on, your aliases should always work (until version 4).
Now, save and close your edited
.zshrc file. To refresh your terminal to use the new alias(es), enter:
To ensure that your commands are pointing to the brew version of python3:
which python3 should respond:
python3: aliased to /opt/homebrew/bin/python3
which python should respond:
python: aliased to /opt/homebrew/bin/python3
NOTE: I have only tested all of the above on Apple silicon macOS Sonoma (which is in developer beta, but should be functionally the same as Ventura).