This guide shows you how to install pip, the Python package manager, on Ubuntu and how to use it to install, upgrade, and remove Python packages. You’ll start with a system check, then install pip for Python 3 (and optionally Python 2), and finish with practical commands for everyday use.
What You’ll Need
- An Ubuntu system (20.04, 22.04, 24.04, or similar) with internet access.
- A user account with sudo privileges (for system-wide installs).
- Python 3 installed (Ubuntu usually includes it). Check with
python3 --version.
Step-by-Step
- Update your package list
Open a terminal and run:sudo apt update
This refreshes the list of available packages from Ubuntu’s repositories. - Install pip for Python 3
Run:sudo apt install python3-pip
This installs pip and its dependencies. Confirm the installation when prompted. - Verify the installation
Check the version with:pip3 --version
You should see output likepip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.12). The exact version depends on your Ubuntu release. - Optional: Install pip for Python 2
Python 2 is deprecated, but if you need it for legacy scripts, run:sudo apt install python-pip
Note that Python 2 is no longer maintained; avoid using it for new projects. - Use pip to install a package
For example, to install therequestslibrary:pip3 install requests
This downloads and installs the package and its dependencies from the Python Package Index (PyPI). - Use pip with sudo (if needed)
If you get a permission error, prefix withsudo:sudo pip3 install requests
However, prefer using a virtual environment to avoid system-wide changes (see Tips). - List installed packages
To see what you have:pip3 list
This shows all installed packages and their versions. - Upgrade a package
To upgrade an existing package to the latest version:pip3 install --upgrade requests - Uninstall a package
To remove a package:pip3 uninstall requests
Confirm when asked. - Search for a package
To find packages on PyPI:pip3 search keyword
Note: thesearchcommand is deprecated in recent pip versions; use the PyPI website instead.
Common Mistakes
- Using
pipinstead ofpip3– On Ubuntu,pipmay point to Python 2 or may not exist. Always usepip3for Python 3. - Installing globally without a virtual environment – This can lead to version conflicts between projects. Use a virtual environment for project-specific dependencies.
- Forgetting to update pip itself – Old pip versions may have bugs. Upgrade pip with
pip3 install --upgrade pip. - Ignoring the “externally managed environment” error – On newer Ubuntu versions, pip may refuse to install system-wide to avoid breaking system packages. This is normal; use a virtual environment.
Tips
- Use virtual environments – Create one with
python3 -m venv myenv, then activate it withsource myenv/bin/activate. Inside, usepip(withoutsudo) to install packages. - Keep pip updated – Run
pip3 install --upgrade pipperiodically to get the latest features and security fixes. - Use
pip3 freezeto generate a requirements file – This lists all installed packages and versions, useful for sharing or replicating environments. - Check package documentation – Some packages have system dependencies; read the docs if installation fails.
Troubleshooting
- “pip3: command not found” – This means pip is not installed. Re-run
sudo apt install python3-pipand check for errors. - “Permission denied” when installing – Use
sudo pip3 install packageor better, create a virtual environment. - “Externally managed environment” error – This happens on Ubuntu 23.04+ where pip is configured to avoid system conflicts. Create a virtual environment:
python3 -m venv myenv, then activate it and usepip install. - Installation fails with “Could not find a version that satisfies the requirement” – Check the package name spelling, ensure you have internet, and try upgrading pip.
- pip is slow or times out – Try using a different PyPI mirror or increase the timeout with
pip3 install --timeout 60 package. - After upgrading pip, it still shows old version – This can happen if you have multiple Python installations. Use
python3 -m pip --versionto check the pip associated with your Python.
Frequently Asked Questions
Do I need to install pip separately if I have Python?
Yes, pip is not always included with Python on Ubuntu. Installing python3-pip ensures you have it.
What is the difference between pip and pip3?
On Ubuntu, pip may refer to Python 2, while pip3 always refers to Python 3. Use pip3 for Python 3 projects.
Can I use pip without sudo?
Yes, if you use a virtual environment or install with the --user flag: pip3 install --user package.
How do I upgrade pip itself?
Run pip3 install --upgrade pip. If you get a permission error, add --user or use sudo.
Why do I get a “externally managed environment” error?
Ubuntu 23.04 and later restrict system-wide pip installs to protect system packages. Use a virtual environment instead.
How do I uninstall a package installed with pip?
Use pip3 uninstall package-name. Confirm the prompt to remove it.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Gmail Notifications Not Working? Fixes That Work
- Fix Thumbnails Not Showing on Network Drives in Windows 11
- Stop Skype Auto-Start in Windows: 5 Fixes
- Fix Windows PowerShell Popping Up
- Print iMessage or Text Conversations on iPhone & iPad
- Madden 20 Crashes on PC: Solved?