share
Stack OverflowCreate a folder using Python
[-6] [3] nitin
[2011-12-16 11:20:12]
[ python py2exe distutils ]
[ http://stackoverflow.com/questions/8533454] [DELETED]

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.

(4) There ought to be an award for the worst question title on SO... - aix
[0] [2011-12-16 11:27:39] Benjamin

You can use os.mkdir to create a directory.


1
[0] [2011-12-16 13:15:54] chip

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-location

2
[0] [2011-12-17 11:47:55] joaquin

I 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
[2] http://docs.python.org/release/3.2/library/base64.html
[3] http://www.wxpython.org/docs/api/wx.tools-module.html

3