. Advertisement .
..3..
. Advertisement .
..4..
Python is an interpreted, object-oriented, high-level, dynamically semantic programming language. It is particularly desirable for Rapid Application Development as well as for usage as a scripting or glue language to tie existing components together due to its high-level built-in data structures, dynamic typing, and dynamic binding. “zsh: command not found: python” is a common error that happens in many ways. Let’s read our article to find the solution to fix it.
When Do You Get The Error “zsh: command not found: python”?
Python is already installed on your MacBook. However, you start typing Python into your terminal. And it gives you the following warning message:
zsh: command not found: python
Why “zsh: command not found: python” Error Is Happening?
Because Apple has removed the Python 2 installation that is a part of the system in its most recent upgrade to Monterey, anyone updating their Mac operating system to Monterey 12.3 may see the problem, “zsh: command not found: python”. There are many ways that depending on the version of Python you need to install on your system. If the version of Python you need is Python 2, consider installing it using Pyenv for a quick workaround. If you want to install Python 3, try installing it using Brew and using the appropriate commands. Below are comprehensive fixes for the zsh: command not found: python error.
How To Solve The Error “zsh: command not found: python”?
Method 1: Set the Python path
The simplest way for you to resolve the error “zsh: command not found: python” is setting the Python path. Let’s follow these steps below to do that:
- You need to find the Python installation path first.
- Start up the terminal.
- Open the /.bash profile file in your text editor. Examples include: atom /.bash profile;
- Add the following line at the bottom of this document:
export PYTHONPATH=”/Users/my_user/code”
5. A text editor file should be saved.
6. Snap the terminal shut.
7. Launch the terminal again. The updated settings are now readable. 8. echo $PYTHONPATH is a type.
8. Hope Now, your mistake must be fixed.
Method 2: Use PyEnv to set up Python 2.7
Depending on the Python version you want to install on your system, there are many solutions to fix the issue zsh: command not found: python. Therefore, using PyEnv to set up Python 2.7 is a workaround for Apple’s latest update (or any other Python 2 version you need). Follow the following steps to furtherr understand about this method.
Step 1: First, you need to install pyenv by using brew to manage several Python versions: brew install pyenv
brew install pyenv
Step 2: With pyenv install —list, list all versions that are installable as the following:
pyenv install --list
Step 3: With pyenv install 2.7.18
, let’s set up Python 2.7.18.
Step 4: Now you have to list the installed versions along with the pyenv versions as below:
pyenv install 2.7.18
Step 5: Python 2.7.18 can be set globally with pyenv global when you run the following command:
pyenv versions
Step 6: Supplement eval "$(pyenv init --path)"
to ~/.zprofile
(or ~/.bash_profile
or ~/.zshrc
, whatever you want).
eval "$(pyenv init --path)" to ~/.zprofile
Step 7: Finally step is to restart the shell, then examine whether Python works or not.
Method 3: Profile should be exported
First, you have to open your terminal and use this command to edit your bash profile.
sudo nano ~/.bash_profile
You’ll be prompted for your password. Simply enter your password and paste the lines below.
PYTHONPATH=”” export PYTHONPATH
Python Path not found? In most cases it ought to be here.
For python
/usr/local/bin/python
For python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
After that, press control + x to exit and y to save. And to return to the terminal window, press “enter”. Then, on a terminal, type the following command to source it.
source ~/.bash_profile
Finally, your error will be completely resolved.
Method 4: Simply run the following command
Now, let’s open your terminal and simply run the following command:
echo "alias python=/usr/bin/python3" >> ~/.zshrc
Please take note that this line python=/usr/bin/python3. Must be followed by the Python version. If you are using Python 3, you should do so right now, and your error should be resolved.
Conclusion
We hope that you will enjoy our “zsh: command not found: python” article. If you have any other questions or concerns about this issue, please leave a comment below. Thank you for reading, we are always excited when one of our posts can provide useful information on a topic like this!
Read more
→ Tips On Solving The Error: “‘python’ is not recognized as an internal or external command”
Leave a comment