Recently I updated my Macintosh operating system to macOS v12.3 (Monterey). I have been getting the error,’zsh: command not found: python’; ever since I made the update when I tried to run my Python code in the terminal:
zsh: command not found: python
Here are the steps I used to solve the error ‘zsh: command not found: python’.
Why zsh command not found python error is seen?
The error, zsh: command not found: python will be seen by everyone who are updating their macintosh operating system to Monterey 12.3 because apple has removed their system-provided Python 2 installer in it’s latest update to monterey. You find more details about it here.
There are different solutions depending on the version of python you require to be installed in your system.
For a simple fix, try installing python through pyenv if the version of python you require is python 2. If you wish to install python 3, try installing python through brew while following all the right commands
A detailed solution to fix the zsh: command not found: python provided below:
How to fix the error zsh: command not found: python?
The error zsh: command not found: python is solved in different ways depending on what python version you wish to install in your system.
Method 1: To install Python 2
So a solution to work around Apple’s new update is to use pyenv to install Python 2.7 (or any other Python 2 version you need).
Step 1: Install pyenv
with brew
to manage different Python versions: brew install pyenv
brew install pyenv
Step 2: List all installable versions with pyenv install --list
pyenv install --list
Step 3: Install Python 2.7.18 with pyenv install 2.7.18
Step 4: List installed versions with pyenv versions
pyenv install 2.7.18
Step 5: Set global python version with pyenv global 2.7.18
pyenv versions
Step 6: Add eval "$(pyenv init --path)"
to ~/.zprofile
(or ~/.bash_profile
or ~/.zshrc
, whichever you need)
eval "$(pyenv init --path)" to ~/.zprofile
Step 7 Relaunch the shell and check that Python works.
Method 2: Install the Python 3
A solution to work around Apple’s new update and install the latest version of python 3 is as follows:
Step 1: reinstall Monterey.
Step 2 install python
via brew
rather than from the official website. It would still return command not found
error.
Step 3: run echo "alias python=/usr/bin/python3" >> ~/.zshrc
in terminal to alias python
with python3
.
echo "alias python=/usr/bin/python3" >> ~/.zshr
This should solve the error zsh: command not found: python
Conclusion
To fix the error zsh: command not found: python; try installing python through pyenv if the version of python you require is python 2. If you wish to install python 3, try installing python through brew while following all the right commands. This should fix your error zsh: command not found: python