0

要在 PyQT 应用程序中启用 jpeg 支持,您必须手动包含qjpeg4.dll.
当 dll 和 pyd 文件没有在最终的 exe 中捆绑在一起时,它可以正常工作。例如,使用 py2exe 您可以执行以下操作:

DATA=[('imageformats',['C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qjpeg4.dll'])]
setup(console=[{"script":"cycotic.py"}], 
    data_files = DATA,
    options={"py2exe":{
        "includes":["sip"],
        "excludes":MODULE_EXCLUDES,
        "bundle_files":3,
        "compressed":False,
        "xref":True}}, 
    zipfile=None)

但是,如果您做同样的事情,并将 dll 捆绑在 exe 中(使用"bundle_files":1),则会失败并显示以下消息:

QObject::moveToThread: Current thread (0x3a16608) is not the object's thread (0x
2dddaf8).
Cannot move to target thread (0x2dddaf8)

QObject::moveToThread: Current thread (0x3a16608) is not the object's thread (0x
2dddaf8).
Cannot move to target thread (0x2dddaf8)

QObject::moveToThread: Current thread (0x3a16608) is not the object's thread (0x
2dddaf8).
Cannot move to target thread (0x2dddaf8)

QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::end: Painter not active, aborted
QPixmap::scaled: Pixmap is a null pixmap

如何正确捆绑应用程序?

4

2 回答 2

2

我有同样的问题,据我所知,py2exe 提供了线索: http: //www.py2exe.org/index.cgi/Py2exeAndPyQt

它显示:......所以你需要将文件夹 PyQt4\plugins\imageformats 复制到 \imageformats。.......这不适用于 bundle_files on。... *这也适用于 bundle_files,但您需要从 bundle 中排除 Qt DLL(使用 dll_excludes 选项)并通过其他一些机制(例如 data_files)将它们添加到可执行文件的目录中。*

以下是我的设置选项,如下所示:

    zipfile=None,
    options = { "py2exe" :{
                           "compressed":1,
                           "includes": my_includes,                           
                           "packages": my_packages,
                           "optimize":2,
                           "bundle_files":1,
                           "dll_excludes":["QtCore4.dll","QtGui4.dll","QtNetwork4.dll"]
                           }}

所以 dist 文件夹包含这些文件(在我的例子中):

  • imageformats(文件夹,包括处理图像的qt插件dll)
  • QtCore4.dll
  • QtGui4.dll
  • QtNetwork4.dll
  • MyExeFile.exe
  • w9xpopen.exe

就这样

于 2012-05-24T13:34:54.450 回答
0

尝试添加pyqt4为包以强制 py2exe 在构建中包含 PyQT 中的所有内容,如下所示:

options={"py2exe":{
        "includes":["sip"],
        "excludes":MODULE_EXCLUDES,
        "packages":["PyQt4"],
        "bundle_files":1,
        "compressed":False,
        "xref":True}}
于 2010-02-08T14:08:46.347 回答