After I updated my MacOS to Monterey, every time I changed the directory in the terminal this message below popped up:
env: python: No such file or directory
But I've already installed Python3. I googled out that Monterey removed Python2.7, but it cannot automatically point to Python3...
It took me 2 hours to find the solution, here they are:
Step 1: Make Sure Python3 Is Installed
whereis python3 to make sure it is installed. At this time, it would show something like this:
Step 2: Find Out the Brew Info
When installing Python3 with Home-brew, it also creates a
libexec folder with unversioned symlinks, which can be found by this command:
brew info python.
After executing this command, there will be something like the below print out:
firstname.lastname@example.org: stable 3.9.7 Interpreted, interactive, object-oriented programming language https://www.python.org/ /usr/local/Cellaremail@example.com/3.9.7 (2,882 files, 49.3MB) Poured from bottle on 2021-09-15 at 22:09:14 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formulafirstname.lastname@example.org License: Python-2.0 ==> Dependencies Build: pkg-config ✔ Required: gdbm ✔, mpdecimal ✔, email@example.com ✔, readline ✔, sqlite ✔, xz ✔ ==> Caveats Python has been installed as /usr/local/bin/python3 Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to `python3`, `python3-config`, `pip3` etc., respectively, have been installed into /firstname.lastname@example.org/libexec/bin
I omit the rest of the print-out because the MOST IMPORTANT part of this is the last line.
Step 3: Update Your $PATH
Put the directory path in that last line to your
.zshrc, depending on which one of them you're using. The complete syntax is:
Save the file and update the shell environment:
source ~/.bash_profile # OR source ~/.zshrc
env: python: No such file or directory problem is solved!
whereis python3 again, the result would be something like this:
python3: /usr/bin/python3 /usr/local/share/man/man1/python3.1.
Your situation may be different from mine, so for more references, I put some links here and hope these would help you.