Finding which modules a Python program uses

Andre M. Descombes amdescombes at testandgo.com
Tue Sep 11 09:38:19 CEST 2001


Thanks Martin,

I will give modulefinder a try!

Regards,

Andre

"Martin von Loewis" <loewis at informatik.hu-berlin.de> wrote in message
news:j41ylfjczk.fsf at informatik.hu-berlin.de...
> "Andre M. Descombes" <amdescombes at testandgo.com> writes:
>
> > I want to distribute my Python application, but I want to deploy only
the
> > modules it uses. The problem is I don't know what they are, for example
if I
> > use the string module, which modules does it need?
> > Is there a way of automatically finding a list of all needed modules for
a
> > program?
>
> Depends on the meaning of "all" and "needed" :-) A simple approach is
> to run "python -v"; that way, you find all the modules that a
> particular run of your application needs - that may not be all modules
> that it could potentially access.
>
> The other option is to look for all import statements. Tools/freeze
> uses that approach, and provides the modulefinder object for that
> purpose. With that approach, you may include modules which might never
> be used, since they only act as fallbacks for cases that never
> occur. Also, if your applications executes code that is created only
> at runtime, or invokes __import__ directly, modulefinder will not find
> these modules.
>
> Hope this helps,
> Martin





More information about the Python-list mailing list