explaingit

bndr/pipreqs

7,452PythonAudience · developerComplexity · 1/5Setup · easy

TLDR

A Python command-line tool that scans your project's source files and generates a requirements.txt listing only the packages your code actually imports, not everything installed on your machine.

Mindmap

mindmap
  root((pipreqs))
    What it does
      Scan import statements
      Generate requirements.txt
      Clean unused deps
    Commands
      pipreqs path
      --diff flag
      --clean flag
    Options
      Ignore directories
      Pin exact versions
      Flexible ranges
    Support
      Python files
      Jupyter notebooks
    Install
      pip install pipreqs
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Generate a clean requirements.txt for a Python project listing only the packages the code actually uses

USE CASE 2

Check whether an existing requirements.txt is out of sync with what your code imports using the --diff flag

USE CASE 3

Remove stale package entries from requirements.txt automatically when you stop using a dependency

Tech stack

Pythonpip

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

pipreqs is a command-line tool for Python projects that automatically figures out which third-party packages your code actually uses and writes them to a file called requirements.txt. That file is the standard way Python projects list their dependencies so someone else can install everything needed to run the code. The standard approach most people know is "pip freeze," which lists every package installed on your computer. The problem is that gives you everything, including packages from other projects you have installed, not just the ones your current project needs. pipreqs solves this by scanning your actual source code files, finding the import statements, and figuring out from those which packages to include. You point it at a folder and it produces a clean, project-specific requirements file. Usage is straightforward. You run "pipreqs /path/to/your/project" and it creates the requirements.txt file in that folder. A handful of options let you customize the behavior: you can ignore certain subdirectories, skip symlinks, force-overwrite an existing file, or print the results to the terminal instead of saving them. There is also a mode option for controlling whether the output pins exact version numbers or uses more flexible version ranges. A comparison and cleanup feature rounds out the tool. The "--diff" flag checks whether your existing requirements.txt matches what your code actually imports, and "--clean" removes entries from requirements.txt that are no longer imported anywhere in your project. Support for Jupyter notebook files is optional and can be turned on with a flag. The project is installable via pip in one line. The README notes the project is looking for maintainers to keep it moving forward.

Copy-paste prompts

Prompt 1
How do I use pipreqs to generate a requirements.txt for my Python project in the src/ directory?
Prompt 2
My requirements.txt has packages I no longer use, how do I run pipreqs --clean to remove them automatically?
Prompt 3
How do I run pipreqs on a project that includes Jupyter notebooks and include their imports in requirements.txt?
Prompt 4
What is the difference between pipreqs and pip freeze, and when should I use each one?
Open on GitHub → Explain another repo

← bndr on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.