Zsh: Command Not Found: Python can happen on any system, however it's significantly more prevalent on MacOS because native Python support was eliminated in MacOS 12.3. Fortunately, this problem is straightforward to resolve.
Since Python 2's system installation was removed from Apple's macOS with the release of macOS Big Sur, zsh command failures like zsh: command not found: pip, zsh: command not found: python vscode, and other zsh difficulties have become increasingly common.
When you try to run a Python command that is not in your shell's PATH, the error zsh: command not found: python appears on the terminal or other servers. Alternatively, Python may not be installed, or the executable file may not be in the system's PATH.
The other reason is that customers who relied on the system-provided Python 2 installation for their Python development environment were affected when Apple removed it. As a consequence, they may have encountered the "zsh: command not found" error while attempting to execute the Python command.
Particularly on macOS, the Python command can occasionally be configured incorrectly. You can try four fixes to fix the error.
If you did not install Python 3 directly but instead upgraded your Mac, you may see that zsh cannot locate the Python command. Anyone who upgrades to Monterey 12.3 on their Mac will find that their copy of Python 2 is suddenly gone. This is because Apple removed the Python 2 installation that came pre-installed on the system.
This problem can be resolved by installing a more current version of Python, such as Python 3, or by managing your Python installations with a version manager, such as Homebrew or Pyenv. These utilities allow you to install and switch between different Python versions. To go around this, follow the instructions below to utilize pyenv to install Python 3.9.6 or any other version you require.
Step 1: To control Python versions, run "brew install pyenv".
Step 2: You may examine every installable version using the "pyenv install -- list" command.
Step 3: The command "Pyenv install 3.9.6" will be executed.
Step 4: Entering "Pyenv versions" yields a list of installed versions.
Step 5: "Pyenv global 3.9.6" configures the default Python version worldwide.
Step 6: If needed, add "eval "$(pyenv init --path)" to "/.zprofile" or "/.bash_profile".
Step 7: Run "$ source /.zprofile" to ensure that Python is still running after reopening the shell.
Apple's deletion of the system-provided Python 2 installation had an impact on users who relied on it for their Python development environment. As a consequence, they may have encountered the zsh: command not found: python error while attempting to execute the python command.
So, the simplest approach to resolve the zsh: command not found: python issue is to use python3 instead of python on the command line.
When you launch Zsh, make sure you have the proper version of Python installed on your Mac and type the correct command (python2 or python3).
This error can occur if Python is not installed on your system or if the Python executable is not in your shell's PATH.
If Python's executable is installed but not immediately available, you can add it to the PATH. To do this, include the following line in your shell profile file (for example, /.zshrc):
Export PATH="$PATH:/usr/bin/python"
To reload the profile file after adding the line, restart your terminal or use the command below your terminal:
source ~/.zshrc
Now, entering the command python should successfully begin the Python interpreter.
A configuration reset can be used to restart Mac Terminal. The steps to factory reset a Mac terminal are as follows:
Step 1. Launch the Terminal program on your macOS device.
Step 2. In the menu bar, select the shell option by tapping on it.
Step 3. Select "Reset" from the menu, or you can press Option + Command + R on your Mac keyboard.
You can reset the Terminal State by following the aforementioned steps. On the Terminal screen, however, no divergence will be seen.
Navigating the intricacies of Zsh errors demands a systematic approach. By following the aforementioned steps, you can bid farewell to the nagging "Zsh: Command Not Found: Python" error and regain control over your development environment.