Discover all non-standard library modules imported by a script

Malcolm Greene python at bdurham.com
Fri Sep 16 19:35:40 EDT 2016


Thanks for your suggestions Chris and Terry.

The answer I was looking for is the modulefinder module which is part of
the standard lib. Works like a charm!

Quote: This module provides a ModuleFinder class that can be used to
determine the set of modules imported by a script. modulefinder.py can
also be run as a script, giving the filename of a Python script as its
argument, after which a report of the imported modules will be printed.

https://docs.python.org/3.5/library/modulefinder.html 

Note there's a similar module for Python 2.7.

--
Malcolm



More information about the Python-list mailing list