How to add an images folder to build executable file in Python. Code is given below
from distutils.core import setup
import glob
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
windows = [{'script': "xtestrecorder.pyw"}],
zipfile = None,
data_files = [("images",'images/XALOGO.png')],
)
this code adds only images folder with in dist folder which is creating when i am running script above script.
You can use os.mkdir
to create a directory.
From your code snippet, it looks similar to this question on SO about setuptools and package data [1]
[1] http://stackoverflow.com/questions/4519127/setuptools-package-data-folder-locationI understand you want the images
folder embedded in your executable.
Py2exe let your data folder on the build folder as you describe, it does not include it in a single exe file.
If you want to collect everything in a file (p.e for distributing your program) the you can use Inno Setup [1]. Inno Setup collects executable and additional dlls and data folders in a setup executable file.
If you need to include just one or a few images that will not change, another option is to encode the image in base64 [2] and to put the image string in a py file to be imported and decoded again when needed. py2exe will include that code in the executable as like any other module. The wxpython wx.tool [3] package has several tools to help doing the conversion from an image to a python script.
[1] http://www.jrsoftware.org/isinfo.php