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)
Mar 23
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.
1 answer
Accepted answer · original discussion
Mar 25
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
$PATHtoo much). - I installed
pythonviabrewrather than from the official website. It would still returncommand not founderror. - I ran
echo "alias python=/usr/bin/python3" >> ~/.zshrcin terminal to aliaspythonwithpython3. - Relaunch the shell or run
source ~/.zshrc
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.
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
Jun 26