skip to content

Python Installation β€” macOS

Install Python 3 on macOS via Homebrew or pyenv. Explains the system-Python warning, PATH precedence, and verification steps.

2 min read 11 snippets yesterday quick read

Python Installation β€” macOS#

# Install Homebrew first if you haven't
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Python
brew install python@3.12

Output:

==> Downloading https://ghcr.io/v2/homebrew/core/python/3.12/manifests/3.12.3
==> Fetching python@3.12
==> Installing python@3.12
...
==> Summary
🍺  /opt/homebrew/Cellar/python@3.12/3.12.3: 3,217 files, 56.7MB

Homebrew symlinks python3 and pip3 automatically. To also get python and pip (without version suffix) in your PATH:

# Add Homebrew Python to PATH (add to ~/.zshrc or ~/.bash_profile)
export PATH="$(brew --prefix python@3.12)/bin:$PATH"
brew install pyenv

# Add to ~/.zshrc
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc

pyenv install 3.12.3
pyenv global 3.12.3

Output:

python-build: use openssl@3 from homebrew
Downloading Python-3.12.3.tar.xz...
Installing Python-3.12.3...
Installed Python-3.12.3 to /Users/you/.pyenv/versions/3.12.3
pyenv versions

Output:

  system
* 3.12.3 (set by /Users/you/.pyenv/version)

The system Python warning#

macOS ships /usr/bin/python3 (a thin stub that prompts you to install Xcode Command Line Tools). It is managed by Apple and should not be used for development.

which python3
/usr/bin/python3          # ❌ this is the system stub
/opt/homebrew/bin/python3 # βœ… this is Homebrew Python

[!WARNING] Never run pip install against the system Python β€” it may interfere with macOS utilities and you cannot upgrade or remove system packages safely. Always work inside a virtual environment or use a Homebrew/pyenv-managed Python.

Verify#

python3 --version
pip3 --version
which python3

Output:

Python 3.12.3
pip 24.0 from /opt/homebrew/lib/python3.12/site-packages/pip (python 3.12)
/opt/homebrew/bin/python3

Common pitfalls#

[!WARNING] PATH order matters β€” if /usr/bin appears before /opt/homebrew/bin in your $PATH, the system stub wins. Make sure your shell config exports the Homebrew prefix early.

[!TIP] Check PATH order: echo $PATH | tr ':' '\n' | grep -n python

Next steps#

python3 -m venv .venv
source .venv/bin/activate

See Virtual Environments for the full guide.