exporting imports to reduce exe size?

R

Ron_Adam

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.

Has anyone tried this?

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

Is it possible to pickle the name space after the imports and then
reload the name space in place of the imports later?

Cheers,
Ron
 
C

Chris Cioffi

My first thought is what if the function you are using uses other
functions(maybe not exported by the module/package)? For example: if
some_func() makes a call to _some_weird_module_specific_func(), how
are you going to make sure you get the
_some_weird_module_specific_func function? This doesn't even start to
work when the function you are interested in is also using functions
from other modules/packages.

Besides, what py2exe is really doing is grabbing the .pyo or .pyc
files and throwing them in a zip file. Is it really worth the effort
to save a 100K or so, at most?

Chris
 
R

Ron_Adam

My first thought is what if the function you are using uses other
functions(maybe not exported by the module/package)? For example: if
some_func() makes a call to _some_weird_module_specific_func(), how
are you going to make sure you get the
_some_weird_module_specific_func function? This doesn't even start to
work when the function you are interested in is also using functions
from other modules/packages.

Besides, what py2exe is really doing is grabbing the .pyo or .pyc
files and throwing them in a zip file. Is it really worth the effort
to save a 100K or so, at most?

Chris

I think in some cases it could save quite a lot more than 100k when
you consider that the module you include to get a single function,
then may include 3 modules for other functions you don't need, and
they in turn do the same.

After looking into it some, I agree it's probably not worth the
effort. Pythons pickle, shelve, and marshal functions don't work on
most module objects, so it's pretty much a dead end.

It would need be doable in a simple and general way to be worth while.

Thanks anyways,

Ron
 
M

Mike Meyer

Ron_Adam said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top