By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,523 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,523 IT Pros & Developers. It's quick & easy.

exporting imports to reduce exe size?

P: n/a

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

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

On Apr 12, 2005 10:54 AM, Ron_Adam <radam2_@_tampabay.rr.com> wrote:

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

--
http://mail.python.org/mailman/listinfo/python-list

--
"I was born not knowing and have had only a little time to change that
here and there." -- Richard Feynman
Jul 18 '05 #2

P: n/a
On Tue, 12 Apr 2005 12:14:38 -0400, Chris Cioffi
<ev********@gmail.com> wrote:
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

Jul 18 '05 #3

P: n/a
Ron_Adam <radam2_@_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 <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.