pythonhomebrewpython-3.11python-3.12

How do I choose default python homebrew version?


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.


Solution

  • 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 python@3.12
    
    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/python@3.12/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 python@3.12
    
    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