How can I fix the "zsh: command not found: python" error? (macOS Monterey 12.3, Python 3.10, Atom IDE, and atom-python-run 0.9.7)
Question:
Since I got the macOS v12.3 (Monterey) 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 the terminal via atom-python-run package (which used to work perfectly fine). The settings for the package go like this:
The which
command in the terminal returns the following (which is odd, because earlier it would return something to just which python
):
I gather the error occurs because the terminal calls for python
instead of python3
, 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 the Python interpreter 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 everything and reinstalled Mac OS X and the Python interpreter only to get the same error.
Answers:
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
via brew
rather than from the official website.
It would still return command not found
error.
- I ran
echo "alias python=/usr/bin/python3" >> ~/.zshrc
in terminal to alias python
with python3
.
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.
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
with brew
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, or run
$ source ~/.zprofile
(Thanks masoud soroush!)
I got zsh: Command not found python
after installing using https://www.python.org/ftp/python/3.10.4/python-3.10.4-macos11.pkg
I solved it by configuring the ENVIRONMENT. I added a line, alias python=/usr/local/bin/python3.10
, into the .zshrc
file (you must be sure it is the true path).
My macOS (Apple silicon):
Darwin Johns-MacBook-Pro.local 21.4.0 Darwin Kernel Version 21.4.0: Mon Feb 21 20:35:58 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T6000 arm64
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.
I have a MacBook Pro with an Apple M1 chip and macOS v12.4 (Monterey).
- I deleted all Python versions and cleared the trash
- Opened Terminal and typed "python"
- This prompted an xcode.app update
- Then I downloaded the latest version of Python from python.org (version 2.10.5)
- Installed that version
- Quit Terminal
- Opened Terminal
- Typed "python3"
It seems to now be there OK.
I installed Python then this error occurred and I just run
echo "alias python=/usr/bin/python3" >> ~/.zshrc
and I t worked.on macOS Monterey 12.4, Python 3.8.9
I use brew install brew install [email protected]
, after installation success I want to know the version of python, I run command python --version
, and I got the problem zsh: command not found: python
.
If you install it successfully, please check in the terminal. It will show you if you got problem in install if not problem you just change command from python --version
to python3 --version
.
you should try
sudo ln -s /usr/bin/python3 /usr/local/bin/python
that solve my problem:)
Since you installed python3.9> (https://python.org/downloads/) , you just need to run everything with python3
instead of python
. You don’t have to downgrade your python to use it… It works fine with suffixing python with 3, i.e. python3
eg.
$ which python3
, python3 --version
, $ python3 script.py
etc
alias python=/usr/bin/python3
This command works but need to re-enter whenever we restart the termian
Try the command python3 --version
if you have installed Python 3.
I just had this problem on a new Macbook Pro with macOS Monterey, and the below worked for me using Homebrew.
Using alias
is not necessary when using Pyenv. Tested with Atom 1.60.0 and atom-python-run 0.9.7.
-
Install pyenv
(https://github.com/pyenv/pyenv#installation) and its dependencies (https://github.com/pyenv/pyenv/wiki#suggested-build-environment):
brew install pyenv
brew install openssl readline sqlite3 xz zlib tcl-tk
-
Install Python 3.10.6 but I assume other 3.x versions should work as well:
pyenv install 3.10.6
-
Add Pyenv to your shell according to the instructions in https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv. In your home directory:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
-
Make the installed Python available everywhere (this can be overridden per project or folder, if necessary):
pyenv global 3.10.6
Now, the output looks like this:
% which python
/Users/jl/.pyenv/shims/python
% python --version
Python 3.10.6
If some scripts still fail, check that you have added Pyenv to the necessary shell startup file(s) as mentioned in step 3 above.
for 3.10.8
install with python with brew command
brew install [email protected]
if you have .zshrc file just edit like this
alias python=’python3′
alias pip =’pip’
export PATH="/opt/homebrew/opt/[email protected]/libexec/bin:$PATH"
if you dont have .zshrc file:
cd
vi .zshrc
and copy/paste the line below
alias python=’python3′
alias pip =’pip’
export PATH="/opt/homebrew/opt/[email protected]/libexec/bin:$PATH"
I had the same problem with fresh MacOS Ventura with Apple Silicon M1 Pro chip. Seems like brew installs to a different location than before on Apple Silicon?
/usr/bin/
folder had a Python executable and the version for it was 3.9.6.
So I installed Python using brew
but then I had to execute it via python3
command so I ran echo "alias python=/opt/homebrew/bin/python3" >> ~/.zshrc
and restarted my terminal. I was prompted with the desired version of Python when executing python
command.
If you are using pyenv and on Mac M1, then try switching the python from system
version to a version that is installed already (ex: pyenv global 3.8.13
, considering 3.8.13 is another version). In order to check what versions installed use pyenv versions
.
If you don’t have another version, try installing a new one and switch to that new environment (ex: pyenv install 3.8.13
). Then install using pip. Everything should work fine. thats what worked for me.
and make sure your pip and python are aliased to pip3 and python3 respective in the respective terminal configuration file.
I First installed python with brew
brew install python
Then I tried linking the python with symlinks using:
brew link python3
And it worked for me.
PS: I was trying to run a shell script and alias approach didn’t work.
Just run the below command in your terminal:
echo "alias python=/usr/bin/python3" >> ~/.zshrc
Basically, here we are saying the terminal to treat python as python3.
Works like magic!
eval "$(pyenv init –path)"
bash starting will be more slow, just suggest
export PATH=$PATH:$HOME/.pyenv/shims
Since I got the macOS v12.3 (Monterey) 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 the terminal via atom-python-run package (which used to work perfectly fine). The settings for the package go like this:
The which
command in the terminal returns the following (which is odd, because earlier it would return something to just which python
):
I gather the error occurs because the terminal calls for python
instead of python3
, 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 the Python interpreter 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 everything and reinstalled Mac OS X and the Python interpreter only to get the same error.
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.
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, or run
$ source ~/.zprofile
(Thanks masoud soroush!)
I got zsh: Command not found python
after installing using https://www.python.org/ftp/python/3.10.4/python-3.10.4-macos11.pkg
I solved it by configuring the ENVIRONMENT. I added a line, alias python=/usr/local/bin/python3.10
, into the .zshrc
file (you must be sure it is the true path).
My macOS (Apple silicon):
Darwin Johns-MacBook-Pro.local 21.4.0 Darwin Kernel Version 21.4.0: Mon Feb 21 20:35:58 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T6000 arm64
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.
I have a MacBook Pro with an Apple M1 chip and macOS v12.4 (Monterey).
- I deleted all Python versions and cleared the trash
- Opened Terminal and typed "python"
- This prompted an xcode.app update
- Then I downloaded the latest version of Python from python.org (version 2.10.5)
- Installed that version
- Quit Terminal
- Opened Terminal
- Typed "python3"
It seems to now be there OK.
I installed Python then this error occurred and I just run
echo "alias python=/usr/bin/python3" >> ~/.zshrc
and I t worked.on macOS Monterey 12.4, Python 3.8.9
I use brew install brew install [email protected]
, after installation success I want to know the version of python, I run command python --version
, and I got the problem zsh: command not found: python
.
If you install it successfully, please check in the terminal. It will show you if you got problem in install if not problem you just change command from python --version
to python3 --version
.
you should try
sudo ln -s /usr/bin/python3 /usr/local/bin/python
that solve my problem:)
Since you installed python3.9> (https://python.org/downloads/) , you just need to run everything with python3
instead of python
. You don’t have to downgrade your python to use it… It works fine with suffixing python with 3, i.e. python3
eg.
$ which python3
, python3 --version
, $ python3 script.py
etc
alias python=/usr/bin/python3
This command works but need to re-enter whenever we restart the termian
Try the command python3 --version
if you have installed Python 3.
I just had this problem on a new Macbook Pro with macOS Monterey, and the below worked for me using Homebrew.
Using alias
is not necessary when using Pyenv. Tested with Atom 1.60.0 and atom-python-run 0.9.7.
-
Install
pyenv
(https://github.com/pyenv/pyenv#installation) and its dependencies (https://github.com/pyenv/pyenv/wiki#suggested-build-environment):brew install pyenv brew install openssl readline sqlite3 xz zlib tcl-tk
-
Install Python 3.10.6 but I assume other 3.x versions should work as well:
pyenv install 3.10.6
-
Add Pyenv to your shell according to the instructions in https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv. In your home directory:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc echo 'eval "$(pyenv init -)"' >> ~/.zshrc
-
Make the installed Python available everywhere (this can be overridden per project or folder, if necessary):
pyenv global 3.10.6
Now, the output looks like this:
% which python
/Users/jl/.pyenv/shims/python
% python --version
Python 3.10.6
If some scripts still fail, check that you have added Pyenv to the necessary shell startup file(s) as mentioned in step 3 above.
for 3.10.8
install with python with brew command
brew install [email protected]
if you have .zshrc file just edit like this
alias python=’python3′
alias pip =’pip’
export PATH="/opt/homebrew/opt/[email protected]/libexec/bin:$PATH"
if you dont have .zshrc file:
cd
vi .zshrc
and copy/paste the line below
alias python=’python3′
alias pip =’pip’
export PATH="/opt/homebrew/opt/[email protected]/libexec/bin:$PATH"
I had the same problem with fresh MacOS Ventura with Apple Silicon M1 Pro chip. Seems like brew installs to a different location than before on Apple Silicon?
/usr/bin/
folder had a Python executable and the version for it was 3.9.6.
So I installed Python using brew
but then I had to execute it via python3
command so I ran echo "alias python=/opt/homebrew/bin/python3" >> ~/.zshrc
and restarted my terminal. I was prompted with the desired version of Python when executing python
command.
If you are using pyenv and on Mac M1, then try switching the python from system
version to a version that is installed already (ex: pyenv global 3.8.13
, considering 3.8.13 is another version). In order to check what versions installed use pyenv versions
.
If you don’t have another version, try installing a new one and switch to that new environment (ex: pyenv install 3.8.13
). Then install using pip. Everything should work fine. thats what worked for me.
and make sure your pip and python are aliased to pip3 and python3 respective in the respective terminal configuration file.
I First installed python with brew
brew install python
Then I tried linking the python with symlinks using:
brew link python3
And it worked for me.
PS: I was trying to run a shell script and alias approach didn’t work.
Just run the below command in your terminal:
echo "alias python=/usr/bin/python3" >> ~/.zshrc
Basically, here we are saying the terminal to treat python as python3.
Works like magic!
eval "$(pyenv init –path)"
bash starting will be more slow, just suggest
export PATH=$PATH:$HOME/.pyenv/shims