Why the Default Python on macOS Isn't Suitable for Development
When you buy a Mac, you get a pre-installed version of the Python interpreter. However, this version:
- Is outdated. Apple rarely updates the system Python, and it almost always lags several major versions behind the current release from the Python Software Foundation.
- Is locked from modification. The system Python resides in the protected system folder (
/usr/bin/). You cannot update it via a package manager or directly, as this would require disabling SIP (System Integrity Protection) and would break macOS. - Is not for development. It is intended solely for the internal needs of the operating system. Installing third-party packages via
pipinto the system Python is impossible or will lead to conflicts.
The correct approach: Install a separate, up-to-date version of Python 3 alongside the system one using a package manager. This is safe and gives you full control.
Method 1: Installation via Homebrew (Recommended for Most Users)
Homebrew is the standard package manager for macOS. It installs packages into its own directory (/opt/homebrew/ on Apple Silicon or /usr/local/ on Intel), leaving the system untouched.
Step 1: Install Homebrew (if not already installed)
Open Terminal (in Applications -> Utilities or via Spotlight) and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Follow the on-screen instructions. After installation, Homebrew may suggest adding itself to your PATH. Do so by following the instructions at the end of the install (usually adding a line to ~/.zprofile).
💡 Tip: Verify the installation by running
brew doctor. It will report any configuration issues.
Step 2: Install Python
Now install Python. Homebrew will install not only the interpreter itself but also the pip package manager, python@3.x utilities, and create a python3 symlink in its bin directory.
brew update
brew install python
This command will install the latest stable version of Python 3 (e.g., 3.12.x).
Step 3: Configure the PATH
This is the most important step; without it, your system will continue using the old Python.
- Determine which shell you are using. Run
echo $SHELL. If the path ends withzsh(the default in macOS Catalina and newer) — edit~/.zshrc. If it ends withbash— edit~/.bash_profileor~/.bashrc. - Open the corresponding file in a text editor (e.g.,
nano ~/.zshrc). - At the very top of the file, add the line:
export PATH="/opt/homebrew/bin:$PATH"- For an Intel-based Mac, the path may be
/usr/local/bin:$PATH.
- For an Intel-based Mac, the path may be
- Save the file (in
nano, this isCtrl+X, thenY, thenEnter). - Apply the changes to your current Terminal session:
source ~/.zshrc # or source ~/.bash_profile
Step 4: Verify the Installation
Run the commands:
python3 --version
# Expected output: Python 3.12.x
which python3
# Expected output: /opt/homebrew/bin/python3 (or /usr/local/bin/python3)
# Check what 'python' points to by default (if you created a symlink, see below)
python --version 2>/dev/null || echo "Command 'python' not configured"
If which python3 shows a path inside /opt/homebrew/ or /usr/local/, and not /usr/bin/, you're on the right track.
(Optional) Create a python command
For historical reasons, many scripts and instructions use the python command instead of python3. Homebrew does not create a python symlink by default to avoid conflicting with the system Python.
If you want the python command to invoke your new Python, create a symlink:
brew link --overwrite python
⚠️ Important: This command will create a symbolic link
pythonin/opt/homebrew/bin/. Since you added this path to the beginning of yourPATH, yourpythoncommand will now point to the Homebrew version. Ensure this is what you want.
Method 2: Version Management with pyenv (For Advanced and Multi-Project Environments)
If you need to frequently switch between different Python versions (e.g., Python 3.10 for one project, 3.12 for another), use pyenv.
Step 1: Install pyenv via Homebrew
brew install pyenv
Step 2: Configure pyenv in your shell
pyenv works by shimming the python command in your current shell. To do this, you need to add its initialization to your shell configuration file (~/.zshrc or ~/.bash_profile).
Add the following lines to the end of the file:
# pyenv configuration
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)" # if you plan to use virtual environments
fi
Run source ~/.zshrc.
Step 3: Install a Specific Python Version
# List available versions for installation
pyenv install --list | grep -E "^\s*3\.(10|11|12)"
# Install the desired version (e.g., 3.12.3)
pyenv install 3.12.3
# Install another (e.g., 3.10.13)
pyenv install 3.10.13
Step 4: Set a Global or Local Version
- Globally (default for all projects):
pyenv global 3.12.3 - Locally (only for the current project directory):
This creates acd /path/to/your/project pyenv local 3.10.13.python-versionfile in the project folder, andpyenvwill automatically switch the Python version when you navigate into it.
Step 5: Verification
python --version
# Should display the version installed via pyenv (e.g., 3.12.3)
pyenv versions
# Will show all installed versions and the currently active one (*)
Setting Up Virtual Environments (The Essential Next Step)
Once you have your system Python set up, you will quickly face the task of isolating dependencies between projects. Never install packages globally (pip install package) into your main Python!
Use virtual environments:
- Built-in
venv(recommended):# Create an environment in a .venv folder python3 -m venv .venv # Activate it (in zsh) source .venv/bin/activate # Now pip install will install packages only into this environment pip install requests # Deactivate deactivate - Management via
pyenv-virtualenv(if you installedpyenv):# Create a virtual environment based on a specific Python version pyenv virtualenv 3.12.3 myproject-env # Activate it for the current folder pyenv local myproject-env
Verification and Next Steps
- Check your PATH. The command
which -a python3should show a path in/opt/homebrew/bin/or~/.pyenv/shims/above/usr/bin/. - Upgrade pip. Even a fresh Python install might have an outdated
pip. Run:python3 -m pip install --upgrade pip setuptools wheel - Install a dependency manager. For most projects, you will need
poetryorpipenv. Install them globally into your new Python:python3 -m pip install poetry - Remove old versions (optional). If you previously installed Python via other methods (e.g., from python.org), you can remove them to avoid confusion. They are typically located in
/Library/Frameworks/Python.framework/.
You have successfully updated Python on macOS! You now have a modern, managed interpreter ready for development with Django, FastAPI, data analysis, or automation.