pyqt jpeg support not working in bundled form

时光总嘲笑我的痴心妄想 提交于 2019-12-24 20:59:37

问题


To enable jpeg support in a PyQT application, you have to manually include the qjpeg4.dll.
It works fine when the dll and pyd file are not bundled together in the final exe. For example with py2exe you can do the following :

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)

However, if you do the same thing, and you bundle the dll in the exe (using "bundle_files":1), it fails with the following message :

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

How can I bundle the application properly ?


回答1:


I've got the same problem, As I know, py2exe has provided the clue: http://www.py2exe.org/index.cgi/Py2exeAndPyQt

It reads: ......so you'll need to copy the folder PyQt4\plugins\imageformats to \imageformats. ....... This won't work with bundle_files on. ... *This will work with bundle_files as well, but you need to exclude the Qt DLLs from bundle (using the dll_excludes option) and add them to the directory with the executable through some other mechanism (such as data_files).*

following is my setup options, like this:

    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"]
                           }}

So the dist folder consists these files (in my case):

  • imageformats (folder, include qt plugin dll to deal with images)
  • QtCore4.dll
  • QtGui4.dll
  • QtNetwork4.dll
  • MyExeFile.exe
  • w9xpopen.exe

that's all




回答2:


Try adding pyqt4 as a package to force py2exe to include everything from PyQT in your build, like this:

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


来源:https://stackoverflow.com/questions/2206737/pyqt-jpeg-support-not-working-in-bundled-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!