1
votes

enter code hereI've a program that uses Enthought's Chaco plots embedded in a pyside (Qt4) GUI. It also uses numpy, but nevermind that. The program runs fine on multiple platforms directly from Python but when I create a .exe for win32 with py2exe I get an error when the .exe is run:

Traceback (most recent call last):
  File "awesome_program.pyw", line 19, in <module>
  File "plotwidget.pyc", line 13, in <module>
  File "enable\api.pyc", line 8, in <module>
  File "enable\base.pyc", line 35, in <module>
  File "enable\colors.pyc", line 246, in <module>
  File "traitsui\qt4\color_editor.pyc", line 21, in <module>
  File "traitsui\editors\__init__.pyc", line 22, in <module>
  File "traitsui\editors\api.pyc", line 29, in <module>
  File "traitsui\editors\list_str_editor.pyc", line 33, in <module>
  File "pyface\image_resource.pyc", line 18, in <module>
  File "pyface\toolkit.pyc", line 73, in <module>
  File "pyface\toolkit.pyc", line 38, in _init_toolkit
  File "pyface\toolkit.pyc", line 31, in import_toolkit
ImportError: No module named init

The setup.py file is:

#! /usr/bin/env python
# setup_win32.py

# Create an .exe for win32 systems.
# Run this with:
#   python setup_win32.py py2exe

import sys
from distutils.core import setup
import py2exe
# from cx_Freeze import setup, Executable

includes = []
includes.append("PySide.QtUiTools")
includes.append("PySide.QtXml")

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(options = {"py2exe": {"dll_excludes":["MSVCP90.dll"],
                            "includes": includes}},
      name='awesomeprogram',
      version='0.01',
      description='A program to visualize stuff.',
      author='John Doe',
      author_email='[email protected]',
      console=[{"script": "awesome_program.pyw"}])

I'm fairly new to Chaco and py2exe, but I get the feeling that something needs to be explicitly included from Enthought's suite in my py2exe setup file? Does anyone have experience with this?

1

1 Answers

3
votes

I haven't used py2exe, but I have some experience with py2app (which I think is similar). It fails to include many of the Enthought/chaco packages, so you need to include them manually in setup.py. Here's what I did:

OPTIONS = dict(
           includes = [
                       # The backends are dynamically imported and thus we need to
                       # tell py2app about them.
                       'kiva.*',
                       'enable.*',
                       'enable.qt4.*',
                       'pyface.*',
                       'pyface.ui.qt4.*',
                       'pyface.ui.qt4.action.*',
                       'pyface.ui.qt4.timer.*',
                       'pyface.ui.qt4.wizard.*',
                       'pyface.ui.qt4.workbench.*',
                       'traitsui.qt4.*',
                       'traitsui.qt4.extra.*',
                       'PyQt4.pyqtconfig',
                       'glob.*'],
           argv_emulation = True)

setup(
      app=APP,
      options={'py2app': OPTIONS},
      setup_requires=['py2app'],
      )

If you replace use a similar OPTIONS (of course replacing py2app with py2exe, and probably PyQt4 with PySide), it may work for you. If it fails with another import, just add it to the include list.