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.
pythonvs.python3: Typically,pythonpoints to an older version, whilepython3specifically calls Python 3. The goal is to havepythonpoint to 3.12 while still being able to usepython3for other 3.x versions.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"brew install python@3.12python3.12 --version- Find the path to the Python 3.12 executable:
which python3.12
- Create a symbolic link (replace
/opt/homebrew/bin/python3.12with the actual path obtained above):ln -s -f /opt/homebrew/bin/python3.12 /opt/homebrew/bin/python
- Add Homebrew's
bindirectory to your system'sPATHin~/.zshrcor~/.bash_profileexport PATH=/opt/homebrew/bin:$PATH
* Apply changes:
```bash
source ~/.zshrc # or source ~/.bash_profile
```
python --versionYou can still use python3 to call explicit versions such as python3.13.
- System Python: Avoid modifying the system Python at
/usr/bin/python. PATHVariable: Ensure/opt/homebrew/binis in yourPATHbefore other Python locations.- Avoid overriding the system
python3executable: Avoid unlinking the system's default python3 executable and relinking it to the Homebrew version. - Alternatives (pyenv): Consider using
pyenvfor 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.