[Distutils] py2exe and eggs

Kevin Dangoor dangoor at gmail.com
Tue Aug 16 17:05:37 CEST 2005


On 8/16/05, Jay Parlar <parlar at gmail.com> wrote:
> Any solutions to this? I don't mind a solution that requires me to add
> something to setup.py that can automatically find any of the eggs I
> use, but I'd really like to avoid adding something to setup.py for
> *each* egg I use.

My solution to this is ugly, but it's not much code (about 50 lines of
trivial stuff) and didn't require delving into py2exe itself.

py2exe really tries to minimize your distribution size and get rid of
all unused modules. My method takes the eggs wholesale, so it's not
quite as space efficient.

Here's what I do:

1) get the list of Distributions using pkg_resources.require(), as
Phillip suggests

2) keep track of the packages in the egg (using the egg's
metadata.get_metadata_lines('top_level.txt'))

3) if the egg is pointing to a directory, add all of the files there
to data_files. If it's a zipped up egg, just add the .egg file to
data_files

4) finally, after building the exe, I create a new library.zip file
that doesn't contain the packages found in step 2. (So, it's not a
minimal set of packages and modules, but it at least isn't duplicating
packages!)

It's not pretty, but it does work. And, in my case, this process works
with both py2exe and py2app and was less work than modifying both of
those packages to do something with the eggs.

Kevin


More information about the Distutils-SIG mailing list