pip
pip is the PyPA-recommended package installer for Python. It installs packages from the Python Package Index (PyPI) and other indexes, supporting wheels, source distributions, VCS URLs, and local paths. Current version is 26.0.1 (bundled with CPython via ensurepip). Releases follow a roughly quarterly cadence aligned with CPython releases. pip is primarily a CLI tool; it intentionally exposes no stable programmatic Python API.
Warnings
- breaking pip.main() was removed years ago and is not a supported API. Calling `import pip; pip.main(...)` will raise AttributeError. pip intentionally exposes no stable programmatic Python API.
- breaking setup.py bdist_wheel build mechanism removed. --no-use-pep517 flag is gone. PEP 517 builds are now always used.
- breaking Python 3.8 support dropped in pip 25.1. Running pip 25.x+ on Python 3.8 is unsupported.
- breaking PEP 668 'externally managed environment' error blocks pip install on modern Debian/Ubuntu/Homebrew system Pythons. pip refuses to modify OS-managed site-packages by default.
- breaking Pre-release specifier semantics changed. Using `<2.0dev` or `>1.0a1` in version specifiers now implies accepting pre-releases for that range (packaging 24.2 behaviour, shipped in pip 24.3+).
- deprecated Using pkg_resources to inspect installed packages is deprecated. pip 25.x emits a warning when the pkg_resources metadata backend is active, and on Python 3.14+ it cannot be used at all.
- gotcha Running `pip install` without an active virtual environment installs into the global or user site-packages, causing version conflicts across projects and potential breakage of system tools.
Install
-
python -m pip install --upgrade pip -
python -m ensurepip --upgrade
Imports
- pip (CLI invocation)
import subprocess, sys subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'requests'])
- importlib.metadata (inspect installed packages)
from importlib.metadata import version, packages_distributions version('requests')
Quickstart
import subprocess
import sys
# Correct way to invoke pip programmatically — always use sys.executable
# so the right interpreter/venv is targeted.
def pip_install(*packages):
subprocess.check_call(
[sys.executable, '-m', 'pip', 'install', *packages],
)
# Example: install/upgrade a package
pip_install('requests>=2.31')
# Verify the installed version using importlib.metadata (no pkg_resources)
from importlib.metadata import version
print('requests', version('requests'))
# List outdated packages (machine-readable JSON)
result = subprocess.run(
[sys.executable, '-m', 'pip', 'list', '--outdated', '--format=json'],
capture_output=True, text=True, check=True,
)
import json
outdated = json.loads(result.stdout)
for pkg in outdated:
print(f"{pkg['name']} {pkg['version']} -> {pkg['latest_version']}")