【问题标题】:Error in py2exe python app using Chaco in pyside在pyside中使用Chaco的py2exe python应用程序出错
【发布时间】:2013-03-22 02:28:35
【问题描述】:

enter code here我有一个程序,它使用嵌入到 pyside (Qt4) GUI 中的 Enthought 的 Chaco 图。它也使用 numpy,但没关系。该程序直接从 Python 在多个平台上运行良好,但是当我使用 py2exe 为 win32 创建 .exe 时,运行 .exe 时出现错误:

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

setup.py 文件为:

#! /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='dude@email.com',
      console=[{"script": "awesome_program.pyw"}])

我对 Chaco 和 py2exe 还很陌生,但我觉得我的 py2exe 安装文件中需要从 Enthought 的套件中明确包含一些内容?有人有这方面的经验吗?

【问题讨论】:

    标签: python pyside py2exe enthought chaco


    【解决方案1】:

    我没有用过 py2exe,但我对 py2app 有一些经验(我认为是类似的)。它无法包含许多 Enthought/chaco 包,因此您需要在 setup.py 中手动包含它们。这是我所做的:

    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'],
          )
    

    如果您替换使用类似的 OPTIONS(当然将 py2app 替换为 py2exe,并且可能将 PyQt4 替换为 PySide),它可能对您有用。如果再次导入失败,只需将其添加到包含列表中即可。

    【讨论】:

    • 现在一个关于 Qt4 图像的新错误,但来自 Enthought:Traceback(最近一次调用最后一次):文件“awesome_program.pyw”,第 19 行,在 文件“plotwidget.pyc”,行13,在 文件“enable\api.pyc”,第 21 行,在 文件“enable\markers.pyc”,第 18 行,在 文件“enable\compiled_pa​​th.pyc”,第 17 行,在 文件“enable\toolkit.pyc”中,第 47 行,在 文件“enable\toolkit.pyc”中,第 40 行,在 _init_toolkit ImportError: Unable to import the image backend for the qt4 toolkit (reason: [ 'I mportError: No module named qt4.image\n']).
    • 您需要追踪根导入并将其包含在上述列表中。动态加载的模块会被 py2exe 遗漏,必须手动添加。
    • 知道这将如何转化为 cx_freeze 吗?
    • @AdamHughes 抱歉,从未使用过 cx_freeze。
    • py2app IIUC 只制作 Mac OSX 二进制文件。我真的在尝试独立于平台。 cx_freeze 到目前为止,伙计们已经让我完成了这个过程,所以我认为这是可能的。在此期间我会尝试 py2app,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多