pyqt jpeg 支持无法以捆绑形式工作

发布于 2024-08-20 00:57:38 字数 1182 浏览 11 评论 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

如何我正确捆绑了应用程序吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半城柳色半声笛 2024-08-27 00:57:38

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

就这些了

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

夏夜暖风 2024-08-27 00:57:38

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

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

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}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文