Reputation: 1583
I have a python application (mainly done using pyqt). I am using py2exe to create the executable, my setup.py looks like this
from distutils.core import setup import py2exe import os
includes=["sqlite3","sip","PyQt4","PyQt4.QtGui","PyQt4.QtCore"]
excludes=[]
packages=[]
dll_excludes=['libgdk-win32-1.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll']
setup(
options={"py2exe": {"compressed": 2,
"optimize": 2,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 2,
"dist_dir": "dist",
"xref": False,
"skip_archive": False,
"ascii": False,
"custom_boot_script": '',
}
},
windows=['myapplication.py'],
data_files = [('', [r'c:\configuration.ini',
r'c:readme.txt'
])]
)
Now the data_files entry allows me to copy a few files to the 'dist' folder, however I would also like to copy my documentation folder, the documentation folder includes a whole bunch of files, html,images,pdfs, about 2MB of documentation stored in a my_app\docs folder. I am not sure how to do this. Can anyone suggest how?
Upvotes: 3
Views: 4487
Reputation: 1141
You're going to have to use a custom function to do this as part of your setup.py
:
def copy_dir():
dir_path = 'YOUR_DIR_HERE'
base_dir = os.path.join('MODULE_DIR_HERE', dir_path)
for (dirpath, dirnames, files) in os.walk(base_dir):
for f in files:
yield os.path.join(dirpath.split('/', 1)[1], f)
Then I set this as my package_data
:
package_data = {
'' : [f for f in copy_dir()]
},
Note that this should also work if you're using data_files
. Make sure that you call the function as part of a list comprehension - apparently setuptools doesn't play nice with list-alikes instead of straight up lists.
Upvotes: 1