Auto generate requirements.txt file
by Anthony
What is a requirements.txt file ?
Usually, a requirement file is just a list of pip install arguments. You can also specify a match version for each. Theses files can be easy install with the pip app pip install -r requirements.txt
. A simple requirement file looks like:
But for a developper, how can we generate it ? I ask me that question when I push on github my last project ExAlias. I figure that you have many solutions to do this.
1. Directly with pip
With this solution, the requirement file will contains a pinned version of everything used in the project who has been installed with pip.
2. Using a third tool
The second method, (that I used) is called pipreqs. A pip requirements.txt file generator based on imports of any project.
Why using it
For 3 reasons
pip freeze
only saves the packages that are installed with pip install in your environment.- pip freeze saves all packages in the environment including those that you don’t use in your current project. (if you don’t have virtualenv)
- and sometimes you just need to create requirements.txt for a new project without installing modules.
how to use it
First of all, you have to install it.
or
After that, the only thing to do is:
Subscribe via RSS