I have a Python app which includes non-Python data files in some of its subpackages. I've been using the include_package_data
option in my setup.py
to include all these files automatically when making distributions. It works well.
Now I'm starting to use py2exe. I expected it to see that I have include_package_data=True
and to include all the files. But it doesn't. It puts only my Python files in the library.zip
, so my app doesn't work.
How do I make py2exe include my data files?
include_package_data
is a setuptools option, not a distutils one. In classic distutils, you have to specify the location of data files yourself, using thedata_files = []
directive.py2exe
is the same. If you have many files, you can useglob
oros.walk
to retrieve them. See for example the additional changes (datafile additions) required to setup.py to make a module like MatPlotLib work with py2exe.There is also a mailing list discussion that is relevant.
I ended up solving it by giving py2exe the option
skip_archive=True
. This caused it to put the Python files not inlibrary.zip
but simply as plain files. Then I useddata_files
to put the data files right inside the Python packages.Here's what I use to get py2exe to bundle all of my files into the .zip. Note that to get at your data files, you need to open the zip file. py2exe won't redirect the calls for you.
The full list of py2exe options is here.
I have been able to do this by overriding one of py2exe's functions, and then just inserting them into the zipfile that is created by py2exe.
Here's an example:
I got the idea from here, but unfortunately py2exe has changed how they do things sense then. I hope this helps someone out.