Since Apple released macOS Big Sur and removed the system installation of Python 2, these zsh command errors such as zsh: command not found: pip, zsh: command not found: python vscode, and other zsh issues started appearing more frequently.
When you try to run a Python command, but it's not in your Shell's PATH, you'll encounter an error like zsh: command not found: python in your terminal or on a server. Another possibility is that Python isn't installed, or its executable file isn't in the system's PATH.
The other reason is that users who relied on the system-provided Python 2 installation to set up their Python development environment were affected when Apple removed it, so they may now encounter a “zsh: command not found” problem when they try to run Python commands.
Solving the "zsh: command not found: python" issue on Mac? Check out the quick navigation below:
Please provide the English content you want to translate, and I'll translate it into Chinese for you as soon as possible.
Solution | Step-by-Step Troubleshooting |
---|---|
Solution 1: Ensure Python 3 is Installed | Install a newer version of Python, such as Python 3, or use a version manager...Full Steps |
Solution 2: Use Python3 Command | The removal of the system-provided Python 2 installation by Apple might affect users...Full Steps |
Solution 3: Update PATH Environment Variable | If Python is not installed on your system, or if the Python executable file...Full Steps |
Solution 4: Restart Terminal | You can restart the Mac terminal using configuration reset. The steps to restore default settings are...Full Steps |
In macOS, the Python command might be misconfigured. You can try four methods to fix the error 'zsh: command not found: python:'
Before you proceed with fixing the zsh: command not found: python issue on your Mac, watch this video first. It will provide you with a quicker and more detailed solution.
If you haven't manually installed Python 3 but have updated your Mac, you may find that zsh can't locate the Python command. Anyone who's upgraded their Mac to Monterey 12.3 will have found that their Python 2 suddenly vanished. That's because Apple removed the pre-installed Python 2 installation from the machine.
Make sure Python is installed, install python3
To resolve this issue, you can either install a newer version of Python, such as Python 3, or use a version manager like Homebrew or pyenv to manage your Python installations. This will allow you to have multiple Python versions installed and easily switch between them. Follow these steps to install Python 3.9.6 or another specific version using pyenv:
1. First, ensure that you have Homebrew installed (if on a Mac) or have an alternative version manager ready. If not, visit the Homebrew website (https://brew.sh/) to install it.
2. Open the Terminal.
3. Install pyenv:
- For Homebrew users:
```
brew update
brew install pyenv
```
- For Ubuntu or Debian users:
```
apt-get update
apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-dev
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
exec $SHELL
```
4. Restart the Terminal and then install the desired Python version (e.g., 3.9.6):
```
pyenv install 3.9.6
```
5. Set the global Python version to 3.9.6 (if you want it as the default):
```
pyenv global 3.9.6
```
6. Verify the installation:
```
python --version
```
Now, you should be able to use Python 3.9.6 or the version you chose. To switch between Python versions for different projects, simply run `pyenv local
Step 1: Manage your Python versions with pyenv, installed via brew: `brew install pyenv`.
Step 2: Use `pyenv install --list` to view all available versions that you can install.
Step 3: Next, type `pyenv install 3.9.6` to install it.
Step 4. Typing "pyenv versions" will list the installed versions.
Step 5: Run `pyenv global 3.9.6` to set the global default Python version to 3.9.6.
If necessary, add `eval "$(pyenv init --path)"` to your `~/.zprofile` or `~/.bash_profile` file.
Step 7. Reopen the terminal and run `$ source ~/.zprofile` to check that your Python setup is still working correctly.
As mentioned above, you should be using the command: brew. If you get the error zsh: command not found: brew, the most likely reason is that Brew is not installed, or it's currently broken or corrupted.
When Apple removed the system-provided Python 2 installation, it affected users who relied on it as their Python programming environment. Consequently, they might encounter the issue "zsh: command not found: python" when attempting to run the python command.
Therefore, the easiest way to fix the zsh: command not found: python issue is to type python3 in your terminal instead of just python.
Make sure you have the correct version of Python installed on your Mac, and that you type the correct command (python2 or python3) for the particular version you're running in Zsh.
This error might occur because Python is not installed on your system, or the Python executable is not in your shell's PATH environment variable.
If you have Python installed but it's not added to your PATH, you can include the Python executable. You can add the following line to your shell configuration file (such as ~/.zshrc):
This command adds the path "/usr/bin/python" to the system's PATH environment variable, allowing the Python interpreter to be run from anywhere in the terminal.
After adding the line, reload the configuration file by restarting the terminal or running the following command in the terminal:
Execute the command: `source ~/.zshrc`
Now, entering the command python should successfully launch the Python interpreter.
You can reset your Mac Terminal using a configuration reset. Here are the steps to factory reset Terminal on Mac:
Step 1: Open the “Terminal” app on your macOS device.
Step 2. In the menu bar, click on “Shell.”
Step 3: From the menu, choose “Reset,” or press Option+Command+R on your Mac keyboard.
You can reset the terminal state by following these steps, but no divergence will be displayed on the terminal screen.
If any of these methods helped you fix the Zsh issue, share it on social media platforms like Facebook, Twitter, Instagram, and so on!
Why is the "zsh: command not found: python" error more common on macOS? This might be because with macOS 12 Monterey, particularly after version 12.3, Mac users might have inadvertently removed the local Python support.
Thus, the “zsh: command not found: python” error can lead to data loss on your Mac. That's because web issues can also cause Zsh errors. Don't worry. This problem is easily fixable with the help of the Mac Data Recovery Wizard.
When permissions like Zsh are denied or when issues are directly related to files, your Mac becomes more vulnerable to attacks. With the Data Recovery Wizard for Mac tool, you can recover deleted or lost data and apps, as well as restore permanently deleted files from Mac's Trash.
Download the tool: Data Recovery Wizard for Mac, and then recover data from Mac in 3 steps:
Step 1. Select the disk to scan
In the main Data Recovery Wizard utility window, all drives connected to your Mac will be listed. Select the drive from which you want to recover lost/deleted files and click on the “Search for Lost Files” button.
Note: Before data recovery, it's better to click “Disk Backup” on the left sidebar to back up your Mac so as to prevent further data loss. After the backup, the software can recover data from the Mac backup, and your computer can write new data again.
Step 2: Select the data/files you lost
The Mac Data Recovery Wizard immediately scans the partition you select and displays the results in the left panel. If you're looking for specific files, you can sort the results to find them.
Step 3: Recover Lost/Deleted Data
Once the scan is finished, preview the files found and then click “Recover” to start retrieving your deleted or lost Mac files.
Even if Python is already installed, the path might not be configured. So, the next step is to add Python to Zsh so that it launches when you enter the python command. To do this, first open Terminal on your Mac, and then run the following command in the terminal:
This command means: Add a line to the user's ZSH configuration file (~/.zshrc) to set an alias for python as /usr/bin/python3.
Now, your zsh configuration will set Python to run as `/usr/bin/python3` whenever you use Python. If you still have issues, check that `python=` points to the path where Python is installed, with the `$` sign.
You can do the following using bash instead of zsh:
Here's the translation in American English: ```shell echo "alias python=/usr/bin/python3" >> ~/.bashrc ``` This command means: Append a line to the user's Bash configuration file, ~/.bashrc, creating an alias that sets `python` to `/usr/bin/python3`. As a result, whenever Python is typed in the terminal, it will run the Python 3 interpreter.
A broken Python installation in your PATH is a common issue. If the first executable the command line finds is corrupted, it will try to start it and then stop looking for other corrupted files. While you should also remove this broken Python installation from your system, a quick fix for the problem is simply to put the new Python directory before the old one in your PATH.
With Python 2 having reached its end-of-life, Apple removed the system-provided installation in macOS 11 Big Sur. This signifies that Python 2 is no longer considered a secure or reliable language version and has ceased to receive active support from the Python development community. As a result, issues like "zsh: command not found: python" have become more common.
This article provides 4 ways to fix it. The Terminal is a useful tool on the Mac and a necessary one for running commands. However, if you don't use the Terminal on your Mac correctly, you may face terrible data loss. Fortunately, tools like Mac Data Recovery Wizard can help!
After learning how to fix the "zsh: command not found: python" issue, you might have more questions. Check here to see if your answer is among them:
**1. How to fix the "command not found" issue in Python?**
In Python, if you encounter a "command not found" problem, it is usually due to one of the following reasons:
1. **Environment Variables Issue**: Make sure the path to the Python executable file is added to the system's PATH environment variable. On Windows, the Python installer typically does this automatically, but on Linux or macOS, you may need to do it manually.
2. **Module Not Installed**: If you're trying to run a Python module (like `pip` or `numpy`) and receive the "command not found" error, check if the module is correctly installed. You can do this by running `python -m pip list` (for Python 3) or `python3 -m pip list` (for Python 2) in your terminal or command prompt to view installed modules.
3. **Using a Python Virtual Environment**: If you're working with a Python virtual environment (like venv or conda), ensure that it is activated. Within a virtual environment, you need to prefix `pip` or `python` commands to point to the correct Python interpreter.
To resolve these issues, try the following steps:
- For environment variable problems, search for a guide specific to your operating system on how to add the Python path to PATH.
- Install missing modules using `pip install
Here, you must select “Path.” As shown in the screenshot below, Python requires a path variable. If Python is missing from the Path, select it from the menu and click Edit. A new screen will appear; click New.
**2. How to Run Python on a Mac Terminal?** To run Python on your Mac Terminal, follow these steps: 1. Open the "Terminal" application. You can find it by: - Using Spotlight search (press `Command + Space`, then type "Terminal" and hit `Enter`). - Navigating through "Applications" > "Utilities" > "Terminal." 2. In the opened terminal window, type the following command to check the installed Python version: ``` python3 --version ``` 3. If Python 3 is already installed, it will display your Python version. If not, you may need to install it using Homebrew, a package manager for macOS. First, install Homebrew by copying the following command, pasting it into the terminal, and pressing `Enter`: ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 4. After installation, use Homebrew to install Python 3: ``` brew install python ``` 5. Now, run `python3 --version` again to verify that the installation was successful. 6. To start the Python interactive shell, type: ``` python3 ``` 7. The terminal will display `>>>`, indicating you can now enter Python code. To exit the Python shell, type `exit()`. You should now be able to run Python on your Mac Terminal.
On a Mac, it's easy: just open the Launchpad, find the Terminal, and type Python at the prompt, which will display which version you have.
How to Fix the "zsh: command not found" Error?
You can try the solutions listed below to fix your Zsh issues. You can read more about how to resolve the Zsh: command not found problem by clicking the link.
How do I delete a file on MacBook using Terminal?
Step 1: Open the Applications folder in Finder, then choose Utilities to launch Terminal on your Mac.
In the Terminal window, type “rm” followed by a space. Then, drag the file into the Terminal to delete it.
Step 3: Press Enter to permanently delete the file.