Python venv + pip Cheat Sheet

Package installation, requirements, editable installs, wheel workflows, and dependency troubleshooting inside Python virtual environments.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Requirements and lock-style workflows
Install a requirements file
python -m pip install -r requirements.txt

# Install project dependencies from requirements.txt.

Install development requirements
python -m pip install -r requirements-dev.txt

# Install a second requirements file for dev-only tools.

Write a requirements snapshot
python -m pip freeze > requirements.txt

# Freeze the current environment to a file.

Compare installed packages to requirements
diff -u requirements.txt <(python -m pip freeze)

# Diff the current environment snapshot against a file.

Install without dependencies
python -m pip install --no-deps mypackage

# Install a package while skipping dependency resolution.

Install from hash-checked requirements
python -m pip install --require-hashes -r requirements.txt

# Require pinned hashes during install.

## Editable and local installs
Editable install of current project
python -m pip install -e .

# Install the current project in editable mode.

Editable install with extras
python -m pip install -e ".[dev]"

# Install development extras from pyproject or setup metadata.

Install from a wheel file
python -m pip install dist/my_package-0.1.0-py3-none-any.whl

# Install a local built wheel into the venv.

Install from a source tarball
python -m pip install dist/my_package-0.1.0.tar.gz

# Install a local source distribution file.

## Wheelhouse and offline patterns
Build wheels for requirements
python -m pip wheel -r requirements.txt -w ./wheelhouse

# Create wheel artifacts for dependencies.

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

# Install using local artifacts and no package index.

Show pip cache directory
python -m pip cache dir

# Print where pip caches downloaded artifacts.

Purge pip cache
python -m pip cache purge

# Clear the local pip cache.

## Dependency debugging
Show package install location
python -m pip show urllib3

# Display metadata and install location for a package.

List outdated packages
python -m pip list --outdated

# Show packages with newer available versions.

Show pip debug info
python -m pip debug

# Print pip environment diagnostics.

Print Python import path
python -c "import sys; print('
'.join(sys.path))"

# Show sys.path for the active environment.

Print imported package version
python -c "import requests; print(requests.__version__)"

# Check the version of an imported module at runtime.

Recommended next

No recommendations yet.