exporting imports to reduce exe size?

Mike Meyer mwm at mired.org
Wed Apr 13 18:34:01 EDT 2005


Ron_Adam <radam2_ at _tampabay.rr.com> writes:

> In looking at ways to reduce the size of exe's created with py2exe,
> I've noticed that it will include a whole library or module even if I
> only need one function or value from it.  
>
> What I would like to do is to import individual functions and then
> export 'write' them to a common resource file and import that with
> just the resources I need in them.

It's not clear you can use a common "resources" file. You need to copy
the namespaces represented by each module into separate namespaces in
the file you're going to import. Multiple files can do this, but there
may be another approach.

> Has anyone tried this?  
>
> I'm considering using pickle to do it, but was wondering if this is
> even a viable idea?  

Yeah, it's viable. LISP has been doing it for quite a while.

However, note that you have to figure out what objects in each module
are needed in each function you call from that module, and recursively
examine each of those objects. It's a non-trivial thing to do, and
will rely heavily on introspection of the objects in question.

     <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list