Discover all non-standard library modules imported by a script
Terry Reedy
tjreedy at udel.edu
Fri Sep 16 17:10:56 EDT 2016
On 9/16/2016 7:29 AM, Malcolm Greene wrote:
> Looking for suggestions on how, given a main script, discover all the
> non-standard library modules imported across all modules, eg. the
> modules that other modules import, etc. I'm not looking to discover
> dynamic imports or other edge cases, just the list modules loaded via
> "import <module>" and "from <module> import ...". I know I could write a
> script to do this, but certainly there must be such a capability in the
> standard library?
>
> Use case: Discovering list of modules to use for building a Python 3.5
> zipapp distributable.
You could check the .__file__ attribute of each module in sys.modules
for 'site-packages', (or more generally, for non-stdlib locations).
--
Terry Jan Reedy
More information about the Python-list
mailing list