ozil
ozil

Reputation: 679

how to list all the packages required for a program in python?

can i list the python packages that are actually required for running exiting python program running in linux. I tried running following commands.

pip3 freeze 
pip3 list

Upvotes: 1

Views: 127

Answers (1)

Donald S
Donald S

Reputation: 1753

To find the modules used by a single python script, you can try to use ModuleFinder:

Create a new python script to analyze the modules your script is using:

New Script:

from modulefinder import ModuleFinder

finder = ModuleFinder()
finder.run_script('MultiProcess.py')

print('Loaded modules:')
for name, mod in finder.modules.items():
    print(('%s: ' % name))
    print((','.join(list(mod.globalnames.keys())[:3])))

print(('-'*50))
print('Modules not imported:')
print(('\n'.join(iter(finder.badmodules.keys()))))

The output is very verbose and detailed

reference: https://docs.python.org/2/library/modulefinder.html

Upvotes: 1

Related Questions