This guide explains how to set Python 3.12 as the default Python version on macOS Sequoia 15.2, so that typing python
in the terminal runs Python 3.12. It also covers keeping the ability to call any Python 3.x version using python3
.
- macOS System Python: macOS has a system Python installation at
/usr/bin/python
, used by the OS and should not be modified. - Multiple Python Versions: You likely have multiple Python versions installed, possibly via Homebrew.
python
vs.python3
: Typically,python
points to an older version, whilepython3
specifically calls Python 3. The goal is to havepython
point to 3.12 while still being able to usepython3
for other 3.x versions.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install [email protected]
python3.12 --version
- Find the path to the Python 3.12 executable:
which python3.12
- Create a symbolic link (replace
/opt/homebrew/bin/python3.12
with the actual path obtained above):ln -s -f /opt/homebrew/bin/python3.12 /opt/homebrew/bin/python
- Add Homebrew's
bin
directory to your system'sPATH
in~/.zshrc
or~/.bash_profile
export PATH=/opt/homebrew/bin:$PATH
* Apply changes:
```bash
source ~/.zshrc # or source ~/.bash_profile
```
python --version
You can still use python3
to call explicit versions such as python3.13
.
- System Python: Avoid modifying the system Python at
/usr/bin/python
. PATH
Variable: Ensure/opt/homebrew/bin
is in yourPATH
before other Python locations.- Avoid overriding the system
python3
executable: Avoid unlinking the system's default python3 executable and relinking it to the Homebrew version. - Alternatives (pyenv): Consider using
pyenv
for more advanced Python version management. - Aliases: You can create aliases like
alias python='python3'
, but it does not change the default executable of the system.
By following these steps, you can make Python 3.12 the default version when using the python
command. Remember to use virtual environments to manage project dependencies.