How to fix "zsh: command not found: python" error? (macOS Monterey 12.3, python 3.10, Atom IDE, atom-python-run 0.9.7)
Solution 1
OK, after a couple of days trying, this is what has worked for me:
- I reinstalled Monterey (not sure it was essential, but I just figured I had messed with terminal and
$PATH
too much). - I installed
python
viabrew
rather than from the official website. It would still returncommand not found
error. - I ran
echo "alias python=/usr/bin/python3" >> ~/.zshrc
in terminal to aliaspython
withpython3
.
Problem solved.
As far as I get it, there is no more pre-installed python 2.x in macOS as of 12.3 hence the error. I still find it odd though that atom-python-run
would call for python
instead of python3
despite the settings.
Solution 2
Anyone updating their macOS to Monterey 12.3 will find that they suddenly no longer have the system-provided Python 2.
The reason for this is that Apple removed the system-provided Python 2 installation (details).
So a workaround/solution for this is to use pyenv to install Python 2.7 (or any other specific version you need).
- Install
pyenv
withbrew
to manage different Python versions:brew install pyenv
- List all installable versions with
pyenv install --list
- Install Python 2.7.18 with
pyenv install 2.7.18
- List installed versions with
pyenv versions
- Set global python version with
pyenv global 2.7.18
- Add
eval "$(pyenv init --path)"
to~/.zprofile
(or~/.bash_profile
or~/.zshrc
, whichever you need) - Relaunch the shell and check that Python works.
Solution 3
If you simply installed Python 3, just use python3
as the command instead of just python
. In my case, I had to install pynev
first via Homebrew (executable brew
) using brew install pyenv
.
But still after using pynev to install Python 2.7.18 and setting it as a global version using pyenv global 2.7.18
, I still ran into an error while trying to run python
.
What worked for me (since I already had Python 3 installed) was by changing my command to use python3
instead of just python
. Of course, this won't be a solution to everyone who may want to use Python 2.

Kig
Hi! I am a newbie python enthusiast currently going through Automate the Boring Stuff with Python course. I come from a business administration background and have no previous coding experience.
Updated on July 09, 2022Comments
-
Kig 11 months
Since I got Monterey 12.3 update (not sure it's related though), I have been getting this error when I try to run my python code in the terminal:
I am using python 3.10.3, Atom IDE, and run the code in terminal via atom-python-run package (which used to work perfectly fine). The settings for the package go like this:
The
which
command in terminal returns the following (which is odd because earlier it would return something to justwhich python
):I gather the error occurs because the terminal calls for
python
instead ofpython3
, but I am super new to any coding and have no idea why it started now and how to fix it. Nothing of these has worked for me:- I deleted and then reinstalled python from python.org.
- I tried
alias python='python3'
(which I saw in one of the threads here). - I tried
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
(which I found here). - To reset zsh and paths, I deleted all associated hidden files in
/local/users/
and ran the terminal once again. - I deleted evetyrhing and reinstalled macos and python only to get the same error.
-
Ava about 1 yearIn some cases a program that you are using doesn't look into your
~/.zshrc
. In my case a more portable solution was to runln -s /opt/homebrew/bin/python3 /usr/local/bin/python
, which doesn't depend on zsh. -
moveson about 1 yearThis should be the accepted answer if the goal is to get Python 2 working on Mac OS Monterey
-
Kambiz about 1 yearWhy do all answers lead to
homebrew
? I recently migrated topyenv
+pipenv
for management only usingmacports
and I am hitting similar errors. In most cases, the user$PATH
is screwed-up. -
Peter Mortensen 11 monthsWhat is "ENVIRONMENT"? Do you mean "environment"? We have italics, bold, and many other formatting options here.
-
CheverJohn 11 months@PeterMortensen I mean that you just add 'alias python=/usr/local/bin/python3.10` into the .zshrc file. That is all.
-
MikhailRatner 11 monthsThanks, adding the
3
behindPython
made the commands work! I wonder why this is...anyone an explanation?