Pip itself doesn’t include an option to generate a minimal requirements.txt file—it only provides commands like pip freeze that list all installed packages in your environment. To generate a minimal list that reflects only the packages your project actually depends on, consider using one of these third-party tools:
-
pipreqs
- Installation:
- Usage:
Navigate to your project directory and run:
This tool scans your project for import statements and creates a requirements.txt based on what it finds.
-
pip-chill
- Installation:
- Usage:
Running:
pip-chill > requirements.txt
outputs a minimal list of packages that are likely only those you explicitly installed.
-
pip-tools
- Installation:
- Usage:
Create a requirements.in with your top-level dependencies, then compile it:
This method helps you maintain minimal direct dependencies while managing transitive ones separately.
Each of these tools offers a different approach, so you can choose the one that best fits your workflow.