Sometimes we need to figure out dependencies of our Python project. I have been using the below two approaches to get it done:
First, we need to install pipreqs:
In order to generate project-level requirement.txt file, run the below command:
requirements file would be saved as- '/path/to/your/project/
Using pipreqs
If we want to collect all the dependencies and store them in a project-level 'requirement.txt' file, then
pipreqs
is an easy and simple solution. This library analyzes the import statements in the project to gather dependencies. First, we need to install pipreqs:
pip install pipreqs
In order to generate project-level requirement.txt file, run the below command:
pipreqs /path/to/your/project/
To read about more advantages of
pipreqs
over
pip freeze
, read it
from here
Using pipdeptree
I have written a more detailed post about visual representation of python packages using 'pipdeptree' library in this blog.
'pipdeptree' provides more advanced options such as listing the dependencies in html format or exporting them in some image format etc.
I have written a more detailed post about visual representation of python packages using 'pipdeptree' library in this blog.
'pipdeptree' provides more advanced options such as listing the dependencies in html format or exporting them in some image format etc.
Here is the most basic use of pipdeptree
Install the package
pip install pipdeptree
Generate dependency graph in console
cd <your project root>
pipdeptree
Comments