pip Requirements and Locking Cheat Sheet

Patterns for requirements files, constraints, repeatable installs, hashes, wheelhouses, and reproducible environments.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Repeatable Installs
Install with required hashes
python -m pip install --require-hashes -r requirements.txt

# Require hash verification for all requirements.

Build a local wheelhouse
python -m pip download -r requirements.txt -d ./wheelhouse

# Download all requirements into a local artifact directory.

Install from a wheelhouse offline
python -m pip install --no-index --find-links ./wheelhouse -r requirements.txt

# Install from local artifacts without contacting indexes.

Install a package without dependencies
python -m pip install --no-deps ./dist/my_package.whl

# Skip resolver dependency installation.

## Constraints and Overrides
Constrain a direct install
python -m pip install pandas -c constraints.txt

# Apply version constraints to a direct install.

Maintain layered requirement files
# requirements-dev.txt
-r requirements.txt
pytest
black
ruff

# Example pattern for base + dev requirement layering.

Example constraints file
urllib3==2.2.2
charset-normalizer==3.3.2
idna==3.7

# Show a constraints file with exact pins.

## Reporting and Auditing
Generate JSON install report
python -m pip install -r requirements.txt --report pip-report.json

# Write a structured report during installation.

Sort frozen requirements
python -m pip freeze | sort > requirements.lock.txt

# Create a sorted requirements snapshot.

List packages as JSON
python -m pip list --format=json

# Output installed packages in JSON format.

Recommended next

No recommendations yet.