• Could not connect to Twitter

Using non-Python files with py2exe

Having used py2exe on a few occasions, each time I’ve stumbled over how to make it include additional data files and exes that my Python code depends on.

I’m writing this entry for personal reference and, just perhaps, I can save someone else the trawl through the docs.

py2exe is a breeze – I’ve used it on Python2.4 and Python2.5 and it ‘just works’ for basic Python code. It works fine with easygui and TKinter code, I’ve had a few troubles with math code (matplotlib, Numpy) but mostly I’ve been able to fix them.

Each investigation took less than 30 minutes and I easily recommend py2exe to distribute Python code.

For reference – see here to add configuration files to the resulting distribution. The ‘configuration files’ can be any files – data, exes, images – whatever you need to include.

You add these files by specifying a list of tuples. Each tuple specifies the destination subdirectory (e.g. ” or ‘destinationDirName’), followed by a list of strings of files to copy.

Here is a simple example – you run it using ‘python setup.py py2exe’ at the commnd prompt.

setup.py:

from distutils.core import setup
import py2exe
# run 'python setup.py py2exe' at command line
# to build the 'dist' distribution directory
setup(console=['mainPythonFile.py'],
data_files=[('destinationDirName',
[r'sourceDirectoryName\aFileToInclude.exe',
r'sourceDirectoryName\dataFile.txt'])]
)

Please share:
  • DZone
  • del.icio.us
  • Reddit
  • Furl
  • Ma.gnolia
  • email
  • StumbleUpon
  • Technorati
  • TwitThis
  • Slashdot
If you enjoyed this post, make sure you subscribe to my RSS feed!

Related posts:

  1. Running ShowMeDo as a daemonised process using daemontools
  2. New Video Published: Working with Word (.doc) files
  3. Optimising Genshi Imports
  4. Growth in Python Project Popularity
  5. Simple easygui File Dialogs

Comments are closed.