python, python3, and python@3 are all currently aliased to python@3.10. We are in the middle of a migration from 3.10 to 3.11.
Did you run brew install python@3.11? Or one of the aliases above?
macos - "brew install python" installs 3.9. Why not 3.10? - Stack Overflow
homebrew - How to make python 3.11 my default python3 with brew - Ask Different
Force a different dependency version
macos monterey - Trying to run Python 3.10 from Terminal after Homebrew install - Stack Overflow
As Henry Schreiner have specified now Python 3.10 is the new default in Brew. Thx for pointing it
--- Obsolete --- The "python3" formula is still 3.9 in the brew system check the doc here: https://formulae.brew.sh/formula/python@3.9#default
The latest version of the formula for 3.9 also support apple silicon.
If you want to use python3.10 you need to run as you described brew install python@3.10
The reason why 3.9 is still the official python3 formula is that generally user using the vanilla python3 are not looking for the latest revision but the more stable. in some months the transition will done.
Python@3.10 is currently keg-only, which means 3.10 is not the default version yet. You can see a message stating this by typing on the terminal: brew info python@3.10:
python@3.10 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
The migration tasks are not yet all done as of July 2022. You can see the latest situation and the details on GitHub: https://github.com/Homebrew/homebrew-core/pull/87075
Note: This applies to any versioned Python installation with Homebrew
After installing Python 3.11, you are given the location of the bin folder with Python 3.11:
==> Caveats
Python has been installed as
/usr/local/bin/python3.11
Unversioned and major-versioned symlinks `python`, `python3`, `python-config`, `python3-config`, `pip`, `pip3`, etc. pointing to
`python3.11`, `python3.11-config`, `pip3.11` etc., respectively, have been installed into
/usr/local/opt/[email protected]/libexec/bin
You can add this folder to be first in your PATH and python or python3 will pick up Python 3.11 (since those are in the folder):
So: add the following line to ~/.zshrc:
export PATH="$(brew --prefix)/opt/[email protected]/libexec/bin:$PATH"
brew --prefix ensures that the correct path is used, regardless of where your brew install resides.
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
~/.zshrcfile 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:
Open up ~/.zshrc with 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
alias python3=/opt/homebrew/bin/python3
# OPTIONAL: ensure "python" command uses homebrew's version of python3
alias python=/opt/homebrew/bin/python3
I use /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:
source ~/.zshrc
To ensure that your commands are pointing to the brew version of python3:
which python3 should respond: python3: aliased to /opt/homebrew/bin/python3
and
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).