Run Python 3’s built-in ensurepip bootstrap module (python3 -m ensurepip --upgrade) to install pip directly into your Python 3 installation—or install the OS package (sudo apt install python3-pip on Debian/Ubuntu) or run the official get-pip.py bootstrap script if your system distribution omits ensurepip.
Basic Example
# 1. Recommended (cross-platform): Use Python 3's built-in ensurepip module
python3 -m ensurepip --upgrade
# 2. Upgrade pip to the latest release using python3 -m pip
python3 -m pip install --upgrade pip
# 3. Verify pip is bound specifically to Python 3
python3 -m pip --version
# Output: pip 25.x from /usr/local/lib/python3.x/site-packages/pip (python 3.x)
Key Details & Platform-Specific Methods
- Always invoke
python3 -m pipinstead of barepiporpip3: On systems with multiple Python installations (such as macOS Homebrew, system Python, conda, or virtual environments), barepiporpip3can point to a different interpreter thanpython3. Prefixing every command withpython3 -m pip install <package>guarantees packages install into that exactpython3environment. - Debian / Ubuntu / WSL (
apt) whereensurepipis stripped: Debian-based Linux distributions splitensurepipandvenvinto separate OS packages (No module named ensurepip). Install both viaapt:
(Note: On modern Ubuntu 23.04+ and Debian 12+, installing packages globally withsudo apt update sudo apt install python3-pip python3-venvpiptriggerserror: externally-managed-environment[PEP 668]—create a virtual environment withpython3 -m venv .venvand install inside it). - Fallback bootstrap via official
get-pip.py: If bothensurepipand an OS package manager are unavailable (e.g., minimal Docker images or custom builds), download and execute PyPA’s official bootstrapper withpython3:curl -sS [https://bootstrap.pypa.io/get-pip.py](https://bootstrap.pypa.io/get-pip.py) -o get-pip.py python3 get-pip.py rm get-pip.py - Windows (
pylauncher): Standard installers frompythonincludepipby default. If it was unchecked during setup, restore and upgrade it using the Windows Python launcher:py -3 -m ensurepip --upgrade py -3 -m pip install --upgrade pip - Creating a virtual environment includes
pipautomatically: Runningpython3 -m venv .venvautomatically bootstraps a fresh, isolatedpipinside.venv/bin/pip(or.venv\Scripts\pip.exeon Windows) without requiring global installation permissions.
Comparison of pip Installation Methods for Python 3
| Method | Command | Platform | Requires Internet? | Best Used When |
|---|---|---|---|---|
ensurepip (Built-in) |
python3 -m ensurepip --upgrade |
macOS, Windows, standard Linux builds | No (bundled wheel) | Restoring or bootstrapping pip into an existing Python 3 installation cleanly. |
| OS Package Manager | sudo apt install python3-pip (or dnf) |
Ubuntu, Debian, Fedora, RHEL | Yes | System-managed Python 3 on Linux servers or WSL where ensurepip is omitted. |
Virtual Environment (venv) |
python3 -m venv .venv |
All platforms | No | Starting any new Python 3 project (automatically provisions isolated python + pip). |
get-pip.py Bootstrapper |
curl -sS https://bootstrap.pypa.io/get-pip.py | python3 |
Minimal containers / custom builds | Yes | Slim Docker images or embedded Python builds lacking ensurepip and OS packages. |
You must log in or register to comment.
