When trying to run python from terminal, it is possible to run into the following issue:
zsh: command not found: python
This can happen on any system, but does occur slightly more commonly on MacOS since they removed native python support in MacOS 12.3. Fortunately this issue is easy to fix.
Step 1: make sure Python is installed
The first thing you should check is that python is installed. You can install python from terminal if you have brew
installed by simply typing:
brew install python
You can also download the executable directly from the Python website to install it. Once python
is installed, try running python
from terminal again. If you still face the same issue, move to step 2.
Step 2: add python to zsh
The next step is to add python
to zsh so that it will run upon typing the python
command. You can do this by running the following in terminal:
echo "alias python=/usr/bin/python3" >> ~/.zshrc
This will configure your zsh profile to run /usr/bin/python3
when python
is run. If you are still facing issues, ensure that python=$
where the $ sign should equal the path python
is installed on.
Step 3: restart terminal
Now that you've done that, simply restart your terminal. When you open it again, your python
command should work successfully.
Top comments (11)
I'm on an M1 Mac, the following worked for me as Step 2 (May 2023)
echo 'export PATH="$(brew --prefix)/opt/python@3/libexec/bin:$PATH"' >> ~/.zshrc
Found that at 'How do I use brew installed Python as the default Python?' on Stackoverflow.
Thanks, this is super helpful
Thanks
thanks @smpnjn
This error occurs because the system-provided Python 2 installation has been removed from Apple's macOS as of macOS 11 Big Sur.
When Apple removed the system-provided Python 2 installation, it impacted users who were relying on it for their Python development environment. As a result, they may have encountered the error message zsh: command not found: python when trying to run the python command.
To resolve this issue, you need to install a newer version of Python (such as Python 3 ) or use a version manager like Homebrew or pyenv to manage your Python installations. These tools allow you to install multiple versions of Python and switch between them as needed.
@smpnjn You can also add this post in your reference list that can be beneficial fo user who want to understand the concept of brew command not found error.
this path work for me
/usr/local/bin/python3
Thanks
Thank you for your help
THANK YOU SO MUCH
Thanks