pip

26.0.1 · active · verified Fri Mar 27

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

Install

Imports

Quickstart

Correct programmatic usage of pip via subprocess. pip has no supported public Python API; always call it through sys.executable to target the active interpreter or venv.

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']}")

view raw JSON →