How do I choose default python homebrew version?
Asked Answered
M

4

8

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.

Malawi answered 20/10, 2023 at 14:6 Comment(2)
How did you install them and in which order? Where are they installed and what's in your PATH? Perhaps look at e.g. pyenv if you need to switch between versions.Robbery
If you don't need the earlier versions then probably worth using brew to delete them.Dallapiccola
U
7

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
Unknown answered 20/10, 2023 at 16:38 Comment(0)
H
5

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
Hypotrachelium answered 13/12, 2023 at 17:49 Comment(0)
I
5

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).

Isauraisbel answered 4/2 at 12:0 Comment(0)
F
0

I installed python 3.11 from brew using

brew install [email protected]

I then changed the PATH variable. But make sure you add the new path variable of the python version ahead of the prev python version preferably in the prefix of the path variable.

get the path of the new python version using

brew info [email protected]

add the following to your .zshrc or .zprofile

export PATH="$(brew --prefix)/path/to/python3.11:$PATH"

if this still doesn't change the python version. try adding an alias in the same file that links python to the new version.

alias python="python3.11"

This should solve the problem but not sure if this is the optimal way to do it.

Finely answered 21/6 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.