How to fix "zsh: command not found: python" on a Mac

Tested: we reproduced this error and confirmed the fix on zsh 5.9 and Python 3.12 on Ubuntu 24.04 (macOS steps researched, not tested on a Mac), November 29, 2026.

macOS doesn’t have a python command any more, only python3. The quickest fix is to type python3 instead:

python3 --version
python3 script.py

If you want python to work too, pick one of the fixes below. The Homebrew PATH fix and a virtual environment give you a real python command. An alias only works when you type it yourself.

We reproduced the error and tested each fix in zsh 5.9 on Linux, with only python3 on the PATH to match a Mac. We didn’t test on a Mac, so the macOS-specific paths come from Apple’s and Homebrew’s documentation.

Why the python command is missing

Apple’s macOS 12.3 release notes say Python 2.7 was removed in that update, and tell developers to use Python 3. Python 2 was the only thing behind the plain python command. Python 3 installs on a Mac (Apple’s Command Line Tools, Homebrew and others) provide python3, so tutorials and tools that still say python hit this error.

In an interactive zsh session the message is:

zsh: command not found: python

From a script or zsh -c it includes a line number, such as zsh:1: command not found: python. Bash says python: command not found. Both exited with status 127, the shell’s code for a command it can’t find.

Fix 1: use python3 (and python3 -m pip)

Nothing to configure. Use python3 wherever a guide says python, and run pip through the same interpreter so packages go to the right place:

python3 -m pip install requests

If python3 also says command not found, Python isn’t installed at all. Install it with Homebrew (brew install python) or Apple’s Command Line Tools. If brew itself isn’t found, start with brew command not found.

Fix 2: add an alias

Add this line to ~/.zshrc, then open a new terminal or run source ~/.zshrc:

alias python=python3

In our test, python --version then printed Python 3.12.3. The limit is that aliases only apply to commands you type. A script starting with #!/usr/bin/env python still failed with:

/usr/bin/env: 'python': No such file or directory

Fix 3: put Homebrew’s unversioned python on your PATH

If you installed Python with Homebrew, it already ships a real python command. It just isn’t on your PATH. Homebrew’s documentation says the default formula installs python3 and pip3 into Homebrew’s bin directory, and that unversioned names such as python and pip go into $(brew --prefix python)/libexec/bin. Add that folder to ~/.zshrc:

export PATH="$(brew --prefix python)/libexec/bin:$PATH"

We tested the same idea with a folder holding a python link to Python 3.12. Once that folder was on the PATH, python --version worked, the #!/usr/bin/env python script ran and whence -a python showed where the command came from. Homebrew’s docs suggest adding the folder only when you need the unversioned names.

Fix 4: use a virtual environment or pyenv

A virtual environment always contains a python command. In our earlier venv test, python3 -m venv .venv created .venv/bin/python and .venv/bin/pip:

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

python works until you run deactivate. This is the usual setup for project work, and it also avoids the externally-managed-environment error from Homebrew’s Python. If you need several Python versions, pyenv provides a python command for whichever version you pick.

Still not found after the fix

  • Open a new terminal. Changes to ~/.zshrc don’t reach terminals that are already open until you run source ~/.zshrc.
  • Check the right file. macOS uses zsh by default, so edit ~/.zshrc, not ~/.bash_profile. echo $SHELL shows which shell you’re in.
  • See what zsh finds. whence -a python lists every match in order. If it prints nothing, the folder isn’t on your PATH.
  • Check your editor. VS Code’s Run button uses the interpreter chosen with “Python: Select Interpreter”, not your terminal alias. Pick a Python 3 interpreter there.

If zsh says permission denied instead of command not found, the file exists but can’t run: see zsh: permission denied. Once Python runs, a missing pip is a separate problem: see no module named pip.

FAQ

Why does my Mac say command not found: python?

Apple removed Python 2.7 in macOS 12.3, and with it the python command. Current Macs only have python3, either from Apple's Command Line Tools or from an installer such as Homebrew. Typing python finds nothing on your PATH, so zsh reports it.

How do I install the python command on a Mac?

Install Python 3 with Homebrew (brew install python), then either use python3 or add $(brew --prefix python)/libexec/bin to your PATH, which is where Homebrew puts the unversioned python and pip commands. A virtual environment also gives you python while it's active.

Is it safe to alias python to python3?

Yes, for typing commands in your own terminal. The alias only exists in interactive zsh sessions, so scripts that start with #!/usr/bin/env python still fail. For those, a real python on your PATH (Homebrew's libexec/bin, pyenv or a venv) works better.

How do I fix zsh: command not found for other commands?

The cause is the same: the program isn't installed, or the folder it lives in isn't on your PATH. Run whence -a <name> to see whether zsh can find it anywhere, check echo $PATH, and open a new terminal after changing ~/.zshrc. For Homebrew itself, see our brew command not found fix.