pipreqs
pipreqs is a Python utility that automatically generates a `requirements.txt` file for a project based on the import statements found in its Python files and Jupyter notebooks. It aims to create a clean, minimal list of direct dependencies, avoiding the inclusion of unused packages or the entire environment as `pip freeze` does. The current version is 0.5.0, and releases occur irregularly, with significant updates like Jupyter support recently added.
Warnings
- breaking Python version compatibility has changed. Older versions of pipreqs supported Python 3.7+, but as of v0.5.0, it requires Python >=3.8.1.
- gotcha pipreqs may include irrelevant packages if virtual environment folders (`.venv`, `env`, etc.) are not explicitly ignored, as it scans all `.py` files in the specified path.
- gotcha Module-to-package mapping issues can lead to incorrect or missing package names (e.g., `kafka` instead of `kafka-python`, or `azure` modules). While mappings are frequently updated, manual intervention may sometimes be necessary.
- gotcha pipreqs primarily detects direct imports. It may not include indirect dependencies (packages required by your direct imports but not explicitly imported in your code) or specific plugins that are only used implicitly.
- gotcha By default, pipreqs will not overwrite an existing `requirements.txt` file, preventing accidental data loss.
Install
-
pip install pipreqs
Quickstart
# Navigate to your project's root directory # Generate requirements.txt for Python files: pipreqs . # Generate requirements.txt including Jupyter notebooks: pipreqs . --scan-notebooks # To print to console without saving to file: pipreqs . --print