pyqt jpeg支持不以捆绑形式工作

时间:2010-02-05 11:18:24

标签: python pyqt4 py2exe

要在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)

但是,如果你做了同样的事情,并且你在exe中捆绑了dll(使用"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

如何正确捆绑应用程序?

2 个答案:

答案 0 :(得分:2)

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

它的内容如下: ......所以你需要将文件夹PyQt4 \ plugins \ imageformats复制到\ imageformats。 ....... 这不适用于上的bundle_files。 ... *这也适用于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

这就是全部

答案 1 :(得分:0)

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

options={"py2exe":{
        "includes":["sip"],
        "excludes":MODULE_EXCLUDES,
        "packages":["PyQt4"],
        "bundle_files":1,
        "compressed":False,
        "xref":True}}