PyQt4 jpeg/jpg 不支持的图像格式 [英] PyQt4 jpeg/jpg unsupported image format

查看:64
本文介绍了PyQt4 jpeg/jpg 不支持的图像格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让 QImage(或 PyQt4 中的任何东西,就此而言)在脚本中加载 jpg 文件.我一直无法找到有关如何让它将 jpg 图像作为脚本加载的任何信息,很多使用 py2exe 进行编译,但我什至无法做到这一点.

I'm trying to get QImage (or anything in PyQt4, for that matter) to load a jpg file in a script. I haven't been able to find any information on how to get it to load a jpg image as a script, lots for compiled using py2exe but I can't even get that far.

花了一些时间来解决这个问题,我关注了一些没有可用的东西.查看我的站点包/PyQt4/plugins/imageformats 文件夹:

Spending some time to resolve this, I've followed a few things with no available. Looking in my site-packages/PyQt4/plugins/imageformats folder I have:

qgif4.dll, qico4.dll,qjpeg4.dll, qmng4.dll, qsvg4.dll, qtga4.dll, qtiff4.dll

根据QtGui.QImageReader.supportedImageFormats(),这是我安装的pyqt4可以使用的

According to QtGui.QImageReader.supportedImageFormats(), this is what my install of pyqt4 can use

[PyQt4.QtCore.QByteArray('bmp'), PyQt4.QtCore.QByteArray('pbm'), PyQt4.QtCore.QByteArray('pgm'), PyQt4.QtCore.QByteArray('png'), PyQt4.QtCore.QByteArray('ppm'), PyQt4.QtCore.QByteArray('xbm'), PyQt4.QtCore.QByteArray('xpm')]

我还确保我的 qt.conf 文件在主 python 目录中,并且有这个

I've also made sure that my qt.conf file is in the main python directory and it has this

[路径]

Prefix = C:/Python27/Lib/site-packages/PyQt4
Binaries = C:/Python27/Lib/site-packages/PyQt4

我试过添加

Plugins = C:/Python27/Lib/site-packages/PyQt4/plugins/imageformats
Plugins = C:/Python27/Lib/site-packages/PyQt4/plugins

没有运气

我在 Windows 7 64b 家庭高级版上运行 python 2.7.2,PyQt4 4.9.1(均为 32b).

I'm running python 2.7.2, with PyQt4 4.9.1(both 32b), on a windows 7 64b Home Premium.

我也尝试过 4.8.1 和 4.8.5(我手头有),但它们都不支持 jpg.我不知所措.我如何让这些重新获得支持?

I've also tried version 4.8.1 and 4.8.5 (which I had on hand) but none of them supported jpg either. I'm at a loss. How do I get these back to being supported?

推荐答案

似乎有两个不同的问题会导致这种情况.看起来我两者都遇到了.

There are two different issues it seems that can contribute to causing this. And it looks like I ran into both.

第一.我以管理员身份"运行 PyQt4 安装程序,这似乎解决了部分问题.所以它需要以管理员身份运行才能让一切正常工作.

1st. I gave running the PyQt4 installer 'as administrator' which seems to have solved part of the issue. So it needs to be run as administrator to get everything to work correctly.

第二.为了正确加载所有插件,必须在加载任何类型的图像之前首先创建 QApplication.

2nd. In order for all the plugins to load properly, the QApplication must be made first before any kind of image is loaded.

所以

app = QtGui.QApplication(sys.argv)

需要先创建.

我的脚本运行为

def main():
    app = QtGui.QApplication(sys.argv)
    win = window()
    win.display()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

自从我以管理员身份安装 PyQt4 后没有改变,但现在可以工作并加载 jpegs 和其他所有内容.

which hasn't changed since I installed PyQt4 as an administrator but now works and loads jpegs and everything else.

我想做的是创建一个脚本,该脚本将由 PyQt4 应用程序调用,但它不会自行运行,因此无需先创建 QApplcation.这就是我遇到问题 #2 的地方

What I was trying to do, was create a script that was going to be called by a PyQt4 application but it wouldn't be run by itself, so there was no need to create a QApplcation first. Which is where I ran into issue #2

参考:http://article.gmane.org/gmane.comp.python.pyqt-pykde/7176/match=jpeg+plugin+not+loading

以管理员身份安装并始终创建 QApplication,即使您不需要它.

Install as administrator and always create the QApplication, even if you don't need it.

此外,如果您只是查看空闲状态下的可用内容:

also if you are just checking to see what's available in idle:

from PyQt4 import QtGui
QtGui.QImageReader.supportedImageFormats()

不会显示所有内容,仍需要运行

won't show everything, still need to run

from PyQt4 import QtGui
import sys
app = QtGui.QApplication(sys.argv)
QtGui.QImageReader.supportedImageFormats()

跟踪起来很烦人,所以希望这对其他人有帮助.

This was annoying to track down, so hopefully this will be helpful to others.

这篇关于PyQt4 jpeg/jpg 不支持的图像格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆