Wonderland
Search…
A Weird Python Command Not Found Problem

Problem Statement

I met a weird problem with the following output:
1
$ python
2
pyenv: python: command not found
3
4
The `python' command exists in these Python versions:
5
3.9.11
6
7
Note: See 'pyenv help global' for tips on allowing both
8
python2 and python3 to be found.
Copied!
What happened??? I just took a nap and turned my computer back on, why did python get lost???

Resolution

Ok... Let me check these paths: /usr/bin and /usr/local/bin :
1
$ ls /usr/bin /usr/local/bin | grep python
2
python3
Copied!
OMG! ONLY python3 EXISTS!
At that moment, I started to recall if I did anything stupid which removed the system python by mistake.
After half an hour of useless attempts, it flashed through my mind that I had just upgraded to macOS Monterey 12.3.1 before I went to sleep, and let me check the release notes:

Python

Deprecations
  • Python 2.7 was removed from macOS in this update. Developers should use Python 3 or an alternative language instead. (39795874)
Now the truth is out, Apple took a shot at me.
This problem can be fixed simply as I have had another python3 installed by Homebrew.
1
$ brew install python3
2
-- snip --
3
Warning: [email protected] 3.9.12 is already installed and up-to-date.
4
To reinstall 3.9.12, run:
5
brew reinstall [email protected]
Copied!
And now you can simply create a symbolic link to it by:
1
sudo ln -s /opt/homebrew/bin/python3 /usr/local/bin/python
Copied!
Finally, try python again:
1
$ python
2
Python 3.9.12 (main, Mar 26 2022, 15:44:31)
3
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
4
Type "help", "copyright", "credits" or "license" for more information.
5
>>>
Copied!

Conclusion

Maybe I should read every release note carefully before I click UPGRADE NOW.

Reference