PyQt4 jpeg/jpg不支持的图像格式。

时间:2022-04-27 16:58:35

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.

我正在尝试获取QImage(或者PyQt4中的任何内容)在脚本中加载一个jpg文件。我还没能找到任何关于如何让它加载jpg图像的信息,很多是用py2exe编译的,但我甚至无法做到这一点。

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

花一些时间来解决这个问题,我已经做了一些没用的事情……查看我的站点包/PyQt4/plugins/imageformat文件夹:

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

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

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

根据qtgui.qimagereader . supportedimageformat(),这是我安装pyqt4可以使用的东西。

[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')]

[font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - theme - font: minor - bidi ' > < span

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

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

[Paths]

(路径)

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

I've tried adding

我试着添加

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

with no luck

没有运气

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

我运行的是python 2.7.2, PyQt4 4.9.1(都是32b),在windows 7 64b Home Premium版。

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?

我也尝试过版本4.8.1和4.8.5(我手头上有),但它们都不支持jpg。我亏本。我怎样才能让这些东西得到支持呢?

2 个解决方案

#1


6  

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

似乎有两种不同的问题导致了这个问题。看起来我都碰到了。

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.

1日。我给运行PyQt4安装程序“作为管理员”,这似乎已经解决了部分问题。因此,它需要作为管理员运行,以使所有工作都能正常工作。

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

2日。为了使所有插件能够正确加载,在加载任何类型的图像之前,必须首先进行q应用程序。

so

所以

app = QtGui.QApplication(sys.argv)

needs to be created first.

需要先创建。

My scripts run as

我的脚本运行

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

if __name__ == '__main__':
    main()

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

自从我作为管理员安装PyQt4之后,它一直没有改变,但是现在可以工作,加载jpeg和其他所有东西。

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

我想要做的是创建一个脚本,它将被PyQt4应用程序调用,但它不会自己运行,所以没有必要先创建一个QApplcation。这就是我遇到的第2个问题?

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

供参考:http://article.gmane.org/gmane.comp.python.pyqt-pykde/7176/match=jpeg + +不+加载插件

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

安装作为管理员,并始终创建QApplication,即使您不需要它。

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.

这很烦人,希望这对其他人有帮助。

#2


0  

Just in case someone is searching for loading plugins, I've created an answer for a more proper question here to allow you basically put plugins in any network shared folder.

如果有人正在搜索加载插件,我已经为一个更合适的问题创建了一个答案,让你可以在任何网络共享文件夹中添加插件。

In short, use QtCore.QCoreApplication.addLibraryPath() instead of qt.conf file.

简而言之,使用QtCore.QCoreApplication.addLibraryPath()而不是qt.conf文件。

#1


6  

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

似乎有两种不同的问题导致了这个问题。看起来我都碰到了。

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.

1日。我给运行PyQt4安装程序“作为管理员”,这似乎已经解决了部分问题。因此,它需要作为管理员运行,以使所有工作都能正常工作。

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

2日。为了使所有插件能够正确加载,在加载任何类型的图像之前,必须首先进行q应用程序。

so

所以

app = QtGui.QApplication(sys.argv)

needs to be created first.

需要先创建。

My scripts run as

我的脚本运行

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

if __name__ == '__main__':
    main()

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

自从我作为管理员安装PyQt4之后,它一直没有改变,但是现在可以工作,加载jpeg和其他所有东西。

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

我想要做的是创建一个脚本,它将被PyQt4应用程序调用,但它不会自己运行,所以没有必要先创建一个QApplcation。这就是我遇到的第2个问题?

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

供参考:http://article.gmane.org/gmane.comp.python.pyqt-pykde/7176/match=jpeg + +不+加载插件

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

安装作为管理员,并始终创建QApplication,即使您不需要它。

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.

这很烦人,希望这对其他人有帮助。

#2


0  

Just in case someone is searching for loading plugins, I've created an answer for a more proper question here to allow you basically put plugins in any network shared folder.

如果有人正在搜索加载插件,我已经为一个更合适的问题创建了一个答案,让你可以在任何网络共享文件夹中添加插件。

In short, use QtCore.QCoreApplication.addLibraryPath() instead of qt.conf file.

简而言之,使用QtCore.QCoreApplication.addLibraryPath()而不是qt.conf文件。