Skip to main content

How to Install and Upgrade pip in Python

pip is Python's standard package manager, essential for installing libraries and managing dependencies. Keeping it updated ensures compatibility and access to the latest features.

Check Current pip Version

Verify pip is installed and see its version:

pip --version
# pip 23.3.1 from /usr/lib/python3.11/site-packages/pip (python 3.11)

# Or more reliably:
python -m pip --version
tip

Using python -m pip ensures you're running pip for the correct Python installation, avoiding confusion when multiple Python versions are installed.

Upgrade pip to Latest Version

Upgrade pip using itself:

# Windows
python -m pip install --upgrade pip

# macOS / Linux
python3 -m pip install --upgrade pip

If you encounter permission errors on Linux/macOS:

# Add --user flag (installs to user directory)
python3 -m pip install --upgrade pip --user

# Or use sudo (not recommended)
sudo python3 -m pip install --upgrade pip

Install pip If Missing

Download and run the official installer:

# Download
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

# Or with wget
wget https://bootstrap.pypa.io/get-pip.py

# Install
python get-pip.py

Using System Package Manager

# Ubuntu/Debian
sudo apt update
sudo apt install python3-pip

# Fedora
sudo dnf install python3-pip

# macOS (with Homebrew Python)
brew install python # pip included

# Arch Linux
sudo pacman -S python-pip

Using ensurepip Module

Python 3.4+ includes a pip bootstrapper:

python -m ensurepip --upgrade

Virtual Environments (Best Practice)

Never install packages globally. Use virtual environments to isolate project dependencies:

# Create virtual environment
python -m venv .venv

# Activate it
# Windows (Command Prompt)
.venv\Scripts\activate

# Windows (PowerShell)
.venv\Scripts\Activate.ps1

# macOS / Linux
source .venv/bin/activate

# pip is now scoped to this environment
pip install requests # Installed only in .venv

Deactivate when done:

deactivate
warning

Installing packages globally with sudo pip install can break system Python packages and cause conflicts. Always use virtual environments or the --user flag.

Common pip Commands

# Install a package
pip install requests

# Install specific version
pip install requests==2.28.0

# Install from requirements file
pip install -r requirements.txt

# List installed packages
pip list

# Show package details
pip show requests

# Uninstall package
pip uninstall requests

# Freeze current packages to file
pip freeze > requirements.txt

Troubleshooting

"pip is not recognized" (Windows)

Python wasn't added to PATH during installation:

# Use Python module syntax instead
python -m pip install package_name

# Or reinstall Python with "Add to PATH" checked

Permission Denied (Linux/macOS)

# Use --user flag
pip install --user package_name

# Or use virtual environment (preferred)
python -m venv .venv && source .venv/bin/activate

SSL Certificate Errors

# Temporary workaround
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org package_name

# On macOS, run certificate installer
/Applications/Python\ 3.x/Install\ Certificates.command

Multiple Python Versions

# Be explicit about which Python
python3.11 -m pip install package_name
python3.10 -m pip install package_name

# Windows py launcher
py -3.11 -m pip install package_name

Quick Reference

TaskCommand
Check versionpython -m pip --version
Upgrade pippython -m pip install --upgrade pip
Fresh installpython get-pip.py
Create venvpython -m venv .venv
Install packagepip install package_name
List packagespip list

Summary

Always use python -m pip rather than bare pip to ensure you're targeting the correct Python installation. Keep pip updated regularly and work within virtual environments to maintain clean, isolated project dependencies. If pip is missing, use get-pip.py or your system's package manager to install it.