How do I choose default python homebrew version?

7.2k views Asked by At

I have all three versions of python 3.10, 3.11 and 3.12 using homebrew. but somehow homebrew defaults to using 3.11 as the default.

when i type which python3, it shows 3.11.6 as the version instead of 3.12. why did it default to 3.11 and how do i change this to 3.12?

I was expecting the latest version 3.12 to be the default.

3

There are 3 answers

0
Iskander14yo On BEST ANSWER

It seems to me that Homebrew defaults to Python 3.11.6 due to the current configuration of your system PATH or the way Homebrew has linked the Python versions. To change the default version to Python 3.12, you might want to try the following steps:

  1. Check Homebrew Linking:
    Check the linking status of Python 3.12 using Homebrew:
brew info [email protected]
  1. Alter the System PATH (if necessary):
    If Python 3.12 is correctly linked but not coming first in the PATH, you may need to alter the system PATH. Update your shell profile (e.g., ~/.zshrc or ~/.bash_profile) to put the directory containing Python 3.12 executable before others:
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
  1. Utilize Homebrew Linking (with caution):
    Alternatively, you might try using Homebrew's link command to change the default Python version. Be cautious as this could lead to broken dependencies:
brew link --overwrite [email protected]
  1. Consider Using pyenv:
    For a more robust solution, consider using pyenv to manage multiple Python versions:
brew install pyenv
pyenv install 3.12.0
pyenv global 3.12.0
0
Michael Oliver On

The issue seems to be in the difference between [email protected] and [email protected] Homebrew Ruby scripts.

3.11 has link_overwrite for python3 which sets a bunch of symlinks in /usr/local/bin/ (which is usually in your $PATH) to use 3.11.

3.12 lacks this and so your shell is not seeing them.

You can rectify this either by modifying your $PATH as in the other reply, or replacing the symlink manually:

cd /usr/local/bin && rm python3 && ln -s ../Cellar/[email protected]/3.12.1/bin/python3.12 python3
0
Dale On

Edit 2024-02-25: About four days ago, the below PR was merged. I believe brew install python should now install Python 3.12.


python3 in Homebrew won't point at 3.12 until this PR is merged. AFAIK Homebrew don't switch the default python3 to the latest version until all the Python software that Homebrew packages are confirmed to work with the new version.

If you really need python3 to point at 3.12 globally right now, I personally like @Iskander14yo's suggestion to use pyenv (above).