Having py2exe include my data files (like include_package_data)
Solution 1
I ended up solving it by giving py2exe the option skip_archive=True
. This caused it to put the Python files not in library.zip
but simply as plain files. Then I used data_files
to put the data files right inside the Python packages.
Solution 2
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 the data_files = []
directive. py2exe
is the same. If you have many files, you can use glob
or os.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.
Solution 3
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.
setup(windows=[target],
name="myappname",
data_files = [('', ['data1.dat', 'data2.dat'])],
options = {'py2exe': {
"optimize": 2,
"bundle_files": 2, # This tells py2exe to bundle everything
}},
)
The full list of py2exe options is here.
Comments
-
Ram Rachum almost 2 years
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 mysetup.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 thelibrary.zip
, so my app doesn't work.How do I make py2exe include my data files?