This error Command '['pip3', 'install', '--upgrade', 'pip']' returned non-zero exit status 1. means that the command to upgrade pip itself failed. This is a very common issue, and usually boils down to permissions or conflicts.
Here are the most common causes and solutions, starting with the simplest and most frequent:
Common Causes:
Permissions: You don't have the necessary administrative privileges to modify the system-wide pip installation.
Conflicting Installations/PATH Issues: Your system might have multiple Python installations, and pip3 might be pointing to a different one than you expect, or there's a conflict.
Corrupted pip or dependencies: The current pip installation might be slightly broken, or its core dependencies (setuptools, wheel) are outdated.
Virtual Environment: If you're supposed to be in a virtual environment but aren't, or vice-versa.
Solutions:
Try these solutions in order until one works:
1. Use sudo (Linux/macOS) or Run as Administrator (Windows) - Common for system-wide installs
This is the most frequent reason for exit status 1 when installing system-wide packages.
On Linux/macOS:
bash
sudo pip3 install --upgrade pip
You'll be prompted for your password.
On Windows:
Search for "Command Prompt" or "PowerShell" in the Start Menu.
Right-click on it and select "Run as administrator".
In the administrator console, run:
cmd
pip3 install --upgrade pip
Note: While sudo or running as administrator often fixes the issue, it's generally discouraged for Python package management unless absolutely necessary, as it can lead to permission issues later. Using virtual environments (Solution 3) is a better practice.
2. Use python3 -m pip (Recommended Best Practice)
This method explicitly tells Python to run the pip module associated with that specific Python interpreter. This helps avoid PATH conflicts or issues with multiple Python installations.
On Linux/macOS:
bash
python3 -m pip install --upgrade pip
If you still get a permission error, try with sudo:
bash
sudo python3 -m pip install --upgrade pip
On Windows:
cmd
py -3 -m pip install --upgrade pip
(If py -3 doesn't work, try python -m pip install --upgrade pip or python3 -m pip install --upgrade pip depending on how your Python is aliased).
If you still get a permission error, run the command prompt as administrator first (as in Solution 1).
3. Use a Virtual Environment (Highly Recommended)
Virtual environments are the standard way to manage Python projects. They create isolated environments where packages are installed locally to your project, avoiding conflicts with system-wide packages and removing the need for sudo/admin privileges.
Navigate to your project directory:
bash
cd /path/to/your/project
(If you don't have a specific project, you can create a new empty directory for this purpose.)
Create a virtual environment:
bash
python3 -m venv venv_name # You can name 'venv_name' anything, e.g., 'myenv'
Activate the virtual environment:
On Linux/macOS:
bash
source venv_name/bin/activate
On Windows:
cmd
venv_name\Scripts\activate
You'll see (venv_name) at the beginning of your prompt, indicating the environment is active.
Now, install/upgrade pip inside the virtual environment:
bash
pip install --upgrade pip
Notice you just use pip, not pip3, because you are inside a Python 3 environment. This should work without any permission issues.
When done, deactivate:
bash
deactivate
4. Upgrade setuptools and wheel first
pip relies on setuptools and wheel. Sometimes, if they are very outdated, the pip upgrade can fail.
Try upgrading them first, with sudo/admin if necessary:
bash
# On Linux/macOS
sudo pip3 install --upgrade setuptools wheel
# On Windows (run as administrator)
pip3 install --upgrade setuptools wheel
Then, retry pip3 install --upgrade pip.
5. Check your Python and pip versions/paths
It might be that pip3 is linked to a Python installation you didn't intend.
Check where pip3 and python3 are located:
bash
which pip3
which python3
pip3 --version
python3 --version
Ensure they correspond to the Python installation you're trying to manage.
6. Reinstall pip (Last Resort)
If none of the above work, you might have a truly broken pip installation. You can try to reinstall it using the get-pip.py script.
Download get-pip.py:
bash
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
# OR (if curl not available)
# wget https://bootstrap.pypa.io/get-pip.py -O get-pip.py
Or simply open the URL in your browser and save the content as get-pip.py.
Run the script with python3:
On Linux/macOS:
bash
sudo python3 get-pip.py
On Windows (Run as administrator):
cmd
python3 get-pip.py
This script will try to install pip, setuptools, and wheel from scratch.
Clean up:
bash
rm get-pip.py
After trying a solution, always retry the original command that failed. If the error persists, provide the full output of the command you're running, including any lines before and after the "non-zero exit status 1" message.