liveBook · Manning

Pip

As explained in Fast by Default

pip is Python's package installer and dependency-management tool.

pip is Python’s package installer and dependency-management tool. Projects record dependencies in requirements.txt or pyproject.toml, then audit them against the imports used by the application. section 8.2.2

Use pip-related workflows to keep production dependencies accurate and compact:

  • Run pipreqs against the project to generate requirements-actual.txt from source-code imports, then compare it with declared requirements. section 8.2.2
  • Classify testing, linting, and debugging packages as development dependencies so production builds can exclude them. section 8.2.2
  • Use pip-tools to resolve declared dependencies and pin versions, limiting unused-package accumulation over time. section 8.2.2
  • Check unexpectedly large wheel files for compiled binaries and consider lighter alternatives. section 8.2.2

Removing unused checkout API dependencies

A checkout API team compared pipreqs output with 23 declared dependencies and found eight unused packages, including obsolete feature dependencies and development tools. Removing them and their indirect dependencies reduced the container image by 40MB, from 2.1GB to 300MB. section 8.2.2

pipreqs /path/to/your/project --savepath requirements-actual.txt

Run pipreqs /path/to/your/project --savepath requirements-actual.txt to generate an import-based dependency list. section 8.2.2

How Fast by Default covers it

How deep it goes
Explains dependency auditing, version pinning, production categorization, and wheel-size checks, but stops short of pip internals.
Examples
Demonstrates pipreqs analysis on a checkout API and compares Python-only packages with compiled-extension wheels.
What it assumes
Assumes a Python project with source imports and dependency declarations in requirements.txt or pyproject.toml.
What you can do after
Diagnose unused Python dependencies with pipreqs and maintain smaller, version-pinned production environments with pip-tools.
How it connects
Connects pip with dependency management, requirements files, production builds, package managers, and wheel files.

Also explained in

Compare how 5 books explain pip →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast by Default. The section links point to the parts of the book it draws on.