gitmyhub

pipreqs

Python ★ 7.5k updated 2mo ago

pipreqs - Generate pip requirements.txt file based on imports of any project. Looking for maintainers to move this project forward.

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.

Pythonpipsetup: easycomplexity 1/5

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.

Where it fits