This article introduces how to generate a requirements.txt file for a Python project using pipreqs.
About pipreqs
“pipreqs” is a tool that automatically detects dependencies in Python projects and generates a requirements.txt file. It analyzes import statements within the project, identifies external packages, and outputs them along with their versions to the requirements.txt file. It’s an incredibly handy tool for managing project dependencies.
What’s good about using it?
You can save yourself the effort of manually creating a requirements.txt file, which can be incredibly convenient when moving your project to different environments or recreating virtual environments.
Installation Guide for pipreqs
$ pip install pipreqs
How to Use
Once the installation is complete, navigate to the directory of your Python project and execute the following command:
$ pipreqs /path/to/your/project
This will analyze Python files within the specified project, generating a requirements.txt file as a result.
Notice
pipreqs does not necessarily provide a perfect list. It may include unnecessary packages due to human error, or essential packages might be missing. Therefore, it is recommended to review the generated requirements.txt and make manual adjustments if necessary.