1

I am running my projects on python=3.6 and i want to list all the modules imported by the python scripts present inside this project/repo/directory so i can build a project specific requirements file for future use. Help me with a script to traverse down the directory tree to list the modules or any available python module to do so.

BlimBlam
  • 336
  • 3
  • 11
  • Does this answer your question? [How to list imported modules?](https://stackoverflow.com/questions/4858100/how-to-list-imported-modules) – buran Feb 25 '20 at 09:36
  • You can use pip freeze to list all libraries installed. – NMAK Feb 25 '20 at 10:09
  • pip freeze will list all the libraries installed in the os / virtual-environment but i wan't to list the libraries and packages specific to the project – BlimBlam Feb 25 '20 at 15:46

1 Answers1

2

I came across the pipreqs package, which generates a requirement.txt file based on the import statements of the project.

Installation:

pip install pipreqs

Usage:

pipreqs /path/to/project

pipreqs will automatically generate a requirements.txt file in root folder of your project.

Limitation: Pipreqs uses imports of projects to generate a requirements.txt file. So, it is very important to note that, pipreqs will not include the plugins required for specific projects. You need to add plugins information manually in a requirement.txt

BlimBlam
  • 336
  • 3
  • 11