Create exe with data files

If the end application has got data files that need to be included then we need a different routine from normal

1. Create a spec file by using the utility Makespec.py

Create a spec file that can be amended to include the data files.

python utils/Makespec.py --icon c:\temp\image.ico --onefile c:\temp\pythonscript.py

Example spec file:

# -*- mode: python -*-
a = Analysis(['c:\\temp\\wxpython.py'],
             pathex=['C:\\Temp\\pyinstaller-2.0\\pyinstaller-2.0'],
             hiddenimports=[],
             hookspath=None)
a.datas += [ ('os-icon.ico', 'C:\\temp\\readcsv\\os-icon.ico', 'DATA')]
 
pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=os.path.join('dist', 'wxpython3.exe'),
          debug=False,
          strip=None,
          upx=True,
          console=False , icon='c:\\temp\\readcsv\\os-icon.ico')

2. Build the file

python utils/Build.py C:\\temp\pyinstaller-2.0\wxpython.spec

3. Add sys._MEIPASS to script

path = getattr(sys, '_MEIPASS', os.getcwd())
os.chdir(path)
ico = wx.Icon('os-icon.ico', wx.BITMAP_TYPE_ICO)
self.SetIcon(ico)

END

If you do not require data files then PyInstaller does a very good job at bundling python into exe especially if the modules used are fairly standard.

python pyinstaller.py --icon c:\temp\image.ico --onefile c:\temp\pythonscript.py

Web links:

http://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile

http://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile

http://www.pyinstaller.org/export/v2.0/project/doc/Manual.html?format=raw#how-one-file-mode-works

http://www.pyinstaller.org/