Python

How to Fix Python on macOS

Resolve Python path conflicts, upgrade to Python 3, and fix pip issues on macOS. Complete troubleshooting guide with a decision flow, symptom-to-fix table, and checklist.

By InventiveHQ Team

On modern macOS, almost every "broken Python" problem is really a path or interpreter mismatch: pip installs a package against one Python interpreter while your terminal runs a different one, so import fails even though the install succeeded. The reliable fix is to stop touching system paths and instead run everything through a per-project virtual environment, where python, python3, pip, and pip3 all resolve to the same isolated interpreter. Apple removed bundled Python 2 in macOS 12.3 (2022), Homebrew now installs to /opt/homebrew on Apple Silicon, and pip refuses to write into the system environment by default (PEP 668) — so guides that predate those changes will send you down the wrong path.

That's the summary an AI Overview would give you. Here's what it can't show you: the actual decision flow for figuring out which Python you're running, a symptom-to-cause-to-fix lookup for the specific errors you'll hit, and a copy-paste recovery checklist. Start with the diagnosis diagram, then jump to whichever row matches your error.

Diagnose it first: which Python is actually running?

Before you change anything, find out which interpreter your shell picks and whether pip is tied to it. Run these four commands — the answers tell you exactly where the mismatch is:

which python3            # which interpreter the shell resolves
python3 -m pip --version # which pip, and which interpreter it belongs to
brew --prefix            # /opt/homebrew (Apple Silicon) or /usr/local (Intel)
echo $PATH               # the search order that decides all of the above

The single most useful command here is python3 -m pip. It forces pip to run as a module of the interpreter you just invoked, which guarantees the install and the import use the same Python. If python3 -m pip install requests works but plain pip install requests doesn't, you've found your bug: bare pip points somewhere else.

macOS Python troubleshooting decision flow A flowchart: run which python3, check whether it points at Homebrew, verify pip matches the interpreter, and if anything is off, create a virtual environment. which python3 Points at brew --prefix /bin? (/opt/homebrew/bin or /usr/local/bin) NO Fix PATH order brew shellenv in ~/.zprofile, reopen shell YES python3 -m pip --version matches that same interpreter? NO Use python3 -m pip so install + import share one interpreter YES Work inside a virtual environment python3 -m venv .venv source .venv/bin/activate Result: pip and python resolve to the same interpreter

Symptom to cause to fix

Match your exact error to a row. These are the failures you actually hit on macOS Ventura, Sonoma, and Sequoia — not the pre-2022 world of system Python 2.

SymptomRoot causeFix
pip: command not found (but python3 works)Homebrew installs pip3, not bare pip; bare pip only exists inside a venvUse pip3 or python3 -m pip, or activate a virtualenv
error: externally-managed-environmentPEP 668 blocks pip from writing into Homebrew's PythonCreate a venv, or use pipx for CLI tools; avoid --break-system-packages
Install succeeds, import says ModuleNotFoundErrorpip and python point at different interpretersRun python3 -m pip install … so both share one interpreter
which python3/usr/bin/python3 not Homebrew/usr/bin sits ahead of Homebrew in PATHAdd eval "$(/opt/homebrew/bin/brew shellenv)" to ~/.zprofile, reopen terminal
python: command not foundNo bare python on modern macOS by designActivate a venv (gives you python), or install python via pyenv
command not found after pip install some-cliThe tool's script dir isn't on PATHPrefer pipx install some-cli, which puts binaries on PATH automatically
Permission denied writing packagesYou previously ran sudo pip and left root-owned filessudo chown -R $(whoami) the affected dir, then never sudo pip again
Wrong version after brew upgradeAn old venv still references the deleted interpreterDelete and recreate the venv: rm -rf .venv && python3 -m venv .venv
Advertisement

Which fix should you reach for?

There isn't one "install Python" answer anymore. Pick the tool that matches the job:

ToolBest forWhen to use it
Homebrew python@3.xA single system-wide Python 3 interpreterYou just need a recent Python to build venvs from
venv (built-in)Per-project dependency isolationEvery project — this is the default answer for "fix my Python"
pipxStandalone CLI tools (black, poetry, httpie)Installing command-line apps without polluting any project
pyenvMultiple Python versions side by sideYou need 3.10 and 3.12, or a specific legacy version
conda / miniforgeScientific stacks with compiled depsData/ML work where NumPy/SciPy wheels fight the toolchain

If you only remember one rule: use venv for projects and pipx for tools, and let Homebrew supply the base interpreter. That combination eliminates the vast majority of macOS path conflicts before they start.

Preventing Python problems

Most issues come down to a mismatch between where Python is installed, what paths are on your PATH, and where pip drops your packages. When those three disagree, you install a package with pip and Python still insists it's missing. Virtual environments fix this permanently by giving each project its own interpreter and its own package directory, so there's nothing to misalign.

Key rule: Never use sudo to install Python packages. sudo pip install writes files as root into a directory your normal user can't manage, and modern pip blocks it anyway. Install into a venv or with pipx, both of which live in your own user space.

Set up a virtual environment (the 30-second version)

cd ~/my-project
python3 -m venv .venv          # create an isolated environment
source .venv/bin/activate      # activate it — prompt now shows (.venv)
pip install requests           # installs into .venv only; bare pip now works
python app.py                  # runs against the venv's interpreter
deactivate                     # leave the environment when done

Inside an activated venv, python, python3, pip, and pip3 all resolve to the same place. That's the entire fix for "pip installed it but Python can't find it."

Recovery checklist

Work top to bottom. Each step is safe and non-destructive until the reinstall at the end.

macOS Python recovery checklist Six ordered steps: confirm the interpreter, check PATH order, use python3 dash m pip, create a venv, reinstall Homebrew Python only if needed, and recreate venvs. Fix in this order 1 which python3 — confirm the interpreter your shell actually runs 2 echo $PATH — make sure brew --prefix /bin comes before /usr/bin 3 python3 -m pip install X — force pip to match the interpreter 4 python3 -m venv .venv — the fix that makes bare pip/python agree 5 brew reinstall python@3.x — only if the interpreter itself is broken 6 rm -rf .venv && recreate — rebuild any venv tied to the old interpreter

Checking system and Python paths

Your PATH tells the shell which directories to search, in order, when you type a command. If Homebrew's bin directory appears after /usr/bin, you'll get Apple's stub Python instead of the one you installed.

Check your PATH and interpreter

echo $PATH
which python3
which pip3

You want to see your Homebrew bin directory (/opt/homebrew/bin on Apple Silicon, /usr/local/bin on Intel) listed before /usr/bin. If it isn't, add Homebrew to your shell startup and reopen the terminal:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile

Inspect where a given Python looks for packages

python3 -c "import sys; print(sys.path)"
python3 -m site           # shows the site-packages directory in use

Comparing sys.path between two interpreters is the fastest way to prove that an install landed in a directory a different Python never searches.

Understanding where Python lives on macOS

Knowing the layout makes path problems obvious rather than mysterious.

  • Apple's stub: /usr/bin/python3 — triggers the Xcode Command Line Tools; fine for quick scripts, not for managing packages.
  • Homebrew (Apple Silicon): interpreter under /opt/homebrew/Cellar/python@3.x/…, symlinked to /opt/homebrew/bin/python3.
  • Homebrew (Intel): the same, but rooted at /usr/local instead of /opt/homebrew.
  • Virtual environment: ./.venv/bin/python and ./.venv/lib/python3.x/site-packages — self-contained and per-project.

There is no bundled Python 2 on macOS 12.3 or later. If a legacy project truly needs it, install Python 2 through pyenv in isolation rather than expecting the OS to provide it.

Reinstalling Python (last resort)

If diagnostics point at a genuinely corrupted interpreter — not just a path mismatch — reinstall through Homebrew:

brew uninstall python@3.12     # match your installed version
brew cleanup
brew install python@3.12
brew link python@3.12

Reinstalling replaces only the interpreter. Your virtual environments hold their own package copies, so any venv built against the old interpreter should be deleted and recreated afterward. Resist the urge to hand-edit .pth files in site-packages or to modify /etc/paths — those changes drift out of sync with Homebrew and reintroduce exactly the mismatches this guide exists to prevent.

Frequently Asked Questions

Why does macOS say "pip: command not found" but Python works?

On modern macOS the Homebrew Python installs its executables as python3 and pip3, not bare python or pip. The bare pip name is only created inside an activated virtual environment. Either call pip3 explicitly, run python3 -m pip install <package> (which guarantees you use the pip tied to that exact interpreter), or activate a venv where pip and python are aliased for you.

Where does Homebrew install Python on Apple Silicon Macs?

On Apple Silicon (M1/M2/M3/M4) Macs, Homebrew installs to /opt/homebrew, so Python lives under /opt/homebrew/Cellar/python@3.x and is symlinked to /opt/homebrew/bin/python3. On older Intel Macs the prefix is /usr/local instead. Run brew --prefix to see which one your machine uses.

Does macOS still include Python 2?

No. Apple removed the bundled Python 2 in macOS 12.3 Monterey (2022), and there is no system Python 2 on macOS Ventura, Sonoma, or Sequoia. If you still need Python 2 for legacy code, install it through pyenv or a container rather than expecting it from the operating system.

Why does "which python3" point to /usr/bin/python3 instead of Homebrew?

/usr/bin/python3 is Apple's Command Line Tools stub, and /usr/bin comes before /opt/homebrew/bin in a default PATH. To prefer Homebrew's Python, make sure /opt/homebrew/bin (or /usr/local/bin on Intel) appears earlier in your PATH by adding eval "$(/opt/homebrew/bin/brew shellenv)" to your ~/.zprofile, then open a new terminal.

Why should I avoid sudo pip install on macOS?

Running sudo pip install writes packages as root into a system or Homebrew directory, creating files your normal user cannot modify later and risking corruption of the interpreter Homebrew manages. Modern pip even blocks installing into the system environment by default. Use a virtual environment or pipx instead, both of which install into your own user space.

How do I fix "externally-managed-environment" errors from pip?

That error means you are trying to pip install into a Homebrew-managed Python, which is protected by PEP 668. The correct fix is to create a virtual environment (python3 -m venv .venv && source .venv/bin/activate) and install there, or use pipx for standalone command-line tools. Only use the --break-system-packages flag as a last resort.

How do I completely reinstall Python with Homebrew?

Run brew uninstall python@3.12 (match your version), then brew cleanup, then brew install python@3.12 and brew link python@3.12. Reinstalling only replaces the interpreter; your virtual environments hold their own copies of packages, so recreate any venv that was built against the old interpreter afterward.

What is the difference between python and python3 on macOS?

There is no bare python command by default on modern macOS. python3 is the real interpreter. Inside an activated virtual environment python and python3 both point at that environment's interpreter, which is the cleanest way to get a working python command without touching system paths.

Why does pip install succeed but Python says the module is not found?

This almost always means pip and python are pointing at different interpreters. You installed the package with one Python's pip and imported it with a different Python. Confirm both with which python3 and python3 -m pip --version, or sidestep the problem entirely by working inside a single activated virtual environment.