BlimBlam
BlimBlam

Reputation: 366

List all the python modules imported by a project

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.

Upvotes: 1

Views: 2477

Answers (1)

BlimBlam
BlimBlam

Reputation: 366

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

Upvotes: 3

Related Questions