How to Fix the zsh command not found pip Error

As a developer, encountering the “zsh: command not found: pip” error can be frustrating, especially when you need to manage Python packages. This error typically occurs when the pip
command is not installed or not accessible in your current environment. In this guide, we’ll walk through the steps to resolve this issue and ensure pip
is available in your Zsh shell.
Why Does This Error Occur?
The “zsh: command not found: pip” error happens when the pip
executable is not present in your system’s PATH
variable or when pip
is not installed at all. This can occur if:
- You recently switched to the Zsh shell.
- Python was installed without including the
pip
package manager. - The
pip
installation path is not correctly added to yourPATH
variable.
Step-by-Step Solution
Step 1: Verify pip
Installation
First, check if pip
is installed on your system by running:
1 | pip3 --version |
If you see the version number, pip
is installed, and you just need to add it to your PATH
. If not, proceed to the next step.
Step 2: Install pip
If pip
is not installed, you can install it using the get-pip.py
script. Follow these steps:
Download the
get-pip.py
script from the official Python website:1
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Run the script using Python:
1
sudo python3 get-pip.py
This command will install pip
on your system.
Step 3: Update Your PATH
Variable
After installing pip
, you need to ensure that the pip
executable is accessible in your shell. Add the following line to your ~/.zshrc
file:
1 | export PATH=$PATH:/usr/local/bin |
Then, reload your Zsh configuration:
1 | source ~/.zshrc |
This step ensures that the directory containing pip
is included in your PATH
.
Step 4: Verify pip
Functionality
To ensure pip
is working correctly, try installing a Python package:
1 | pip install requests |
If the installation is successful, you have resolved the “zsh: command not found: pip” error.
Additional Tips
Using Virtual Environments: It’s recommended to use Python’s virtual environments to manage dependencies. You can create a virtual environment using:
1
2python3 -m venv myenv
source myenv/bin/activateThis approach isolates dependencies and avoids conflicts.
Check Python Version: Ensure you are using the correct version of Python. Sometimes, systems may default to an older version. You can specify the version explicitly by using
python3 -m pip
.Update
pip
: If you encounter issues, ensure you have the latest version ofpip
by running:1
python3 -m ensurepip --upgrade
Conclusion
The “zsh: command not found: pip” error is common but easily resolved by verifying pip
installation, updating your PATH
variable, and ensuring your environment is correctly configured. By following these steps, you can quickly fix the issue and continue managing your Python packages seamlessly.