Learning which modules were loaded

Gary Herron gherron at islandtraining.com
Fri Jun 6 17:40:39 EDT 2008


James Stroud wrote:
> I am rolling up a distribution of a program I wrote. It uses 
> matplotlib with tkagg so the bundle is HUGE (47 MB, 14 MB after bz 
> compression). Is there any way to run the program, put it through all 
> of its paces, and then inspect which modules were loaded. I would like 
> to gather these in a list and delete any others that py2app and py2exe 
> attempt to include. Currently, these (or py2app, at least) use 
> dependency graphing and icnlude everything belonging to pylab, 
> matplotlib, and numpy by default. I don't want everything, I only want 
> what my program needs to run. For example, some modules are imported 
> by functions (in Pmw, for example) that never get called. I don't want 
> to include these.
>
> Thanks in advance for any help.
>
> James
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Import sys, then look at sys.modules.  It's a dictionary that contains 
all the imported modules, but I suspect you'll find that it's much 
easier to let py2app and py2exe determine what's imported than it is to 
go through sys.modules yourself.

Gary Herron




More information about the Python-list mailing list