Efficient pip Installation on Ubuntu: Engineering Workflow
Any Ubuntu-based Python environment—production or development—relies on pip for reliable package management. While Ubuntu ships with Python installed out-of-the-box, pip is typically omitted from minimal and container images, and even on desktops its version may quickly become outdated.
Pre-install Check
First, confirm if pip or pip3 is already present in your environment. False assumptions here often waste time in automated provisioning.
pip3 --version
If pip3 is missing:
Command 'pip3' not found, but can be installed with:
sudo apt install python3-pip
If you see a version string, check that it’s not outdated—some distributions ship with pip 9.x by default, which lacks support for many modern Python libraries.
Refresh Your Package Index
Installations failing due to outdated package metadata can be subtle and frustrating. Synchronize your package list before any installation:
sudo apt update
Standard pip Installation on Ubuntu 20.04/22.04+
Almost all recent Ubuntu LTS releases (20.04 Focal and 22.04 Jammy, as of writing) provide pip3 via the default repositories:
sudo apt install python3-pip
Note: The default pip3 version from apt
is almost always lagging behind the current upstream. For standard development it suffices, but for latest features or to avoid PyPI deprecation warnings, see the manual upgrade section below.
Verifying Installation
pip3 --version
# Example output:
# pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
If this outputs a valid version path, installation is complete.
Installing and Verifying a Package
Quick end-to-end test: Install requests
, a common HTTP library. This step also surfaces broken Python path issues.
pip3 install --user requests
Note: Use --user
when not working as root to avoid changing system site-packages.
Sanity-check import:
$ python3 -c "import requests; print(requests.__version__)"
# 2.25.1 (or similar)
If you encounter ModuleNotFoundError: No module named 'requests'
after installation, inspect your $PATH
and $PYTHONPATH
; conflicting Python installations (eg. conda, pyenv) are a common cause.
Upgrading pip Beyond Distribution Defaults
Critical when PyPI deprecates older clients, or advanced resolver functionality is needed:
python3 -m pip install --upgrade --user pip
To avoid permissions issues with system site-packages, always prefer the --user
flag unless working inside a controlled venv.
Non-obvious Issue: The pip/pip3 Aliasing
Pip for Python 2 is now obsolete (EOL since Jan 2020), but the pip
alias may still refer to python2-pip
or be missing.
Engineers expecting pip
to reference Python 3 can safely alias in their shell config:
echo "alias pip=pip3" >> ~/.bashrc
Gotcha: Some system tools still expect pip
to refer to Python 2. Validate with which pip
before aliasing in shared environments.
When Not to Use APT pip
When building Docker images or deploying CI runners, prefer installing Python and pip through the official python.org installers or get-pip.py
script for full control over versions and isolation from system libraries.
Virtual Environments
Production codebases, or anything where dependency isolation matters, should combine pip with Python’s built-in venv
:
python3 -m venv ~/myenv
source ~/myenv/bin/activate
pip install flask
Note: This virtual environment’s pip is always up-to-date and avoids polluting global Python paths.
Table: Command Reference
Purpose | Command |
---|---|
Check pip version | pip3 --version |
System-wide install | sudo apt install python3-pip |
User-local install pkg | pip3 install --user <package> |
Upgrade pip (user) | python3 -m pip install --upgrade --user pip |
Create virtual env | python3 -m venv ./env && source ./env/bin/activate |
Summary (Mid-Article)
For most Ubuntu users, sudo apt install python3-pip
is sufficient. Power users and automation workflows often require explicit version management and consideration of PATH
/PYTHONPATH
collisions.
Practical advice: Always verify your Python and pip binaries refer to the intended interpreter, especially on systems with multiple Python installations or in Docker-based setups.
Known issue: Ubuntu Docker base images typically omit pip and require manual installation via apt or an upstream installer.