【问题标题】:pyqt jpeg support not working in bundled formpyqt jpeg 支持不以捆绑形式工作
【发布时间】:2010-02-05 11:18:24
【问题描述】:

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

如何正确捆绑应用程序?

【问题讨论】:

    标签: python pyqt4 py2exe


    【解决方案1】:

    我也遇到了同样的问题,据我所知,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

    就是这样

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 已修改 pyqt -> PyQt4 以具有有效的包名称,但它失败了。显然 PyQt4 不喜欢以这种方式包含在内。它失败并显示:错误:编译 'C:\Python26\lib\site-packages\PyQt4\uic\port_v3\proxy_base.py' failed SyntaxError: invalid syntax (proxy_base.py, line 4)
      • 这是proxy_base.py 中的错误?将 proxy_base 添加到您的排除中并查看它是否构建
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-09
      相关资源
      最近更新 更多