在py2exe编译的Python脚本中为QImage启用JPEG支持? [英] Enabling JPEG support for QImage in py2exe-compiled Python scripts?

查看:82
本文介绍了在py2exe编译的Python脚本中为QImage启用JPEG支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过PyQt4在Python脚本的QImage对象中使用JPEG图像.

I'm trying to use a JPEG image in a QImage object from a Python script, with PyQt4.

脚本本身可以完美运行,可以加载图像,并且可以对其进行操作和渲染.但是,当我尝试使用py2exe编译"此脚本时,除JPEG图像外,其他所有东西都可以正常工作.用等效的PNG代替它是可行的,但是由于我的程序是从网络上下载图像的,因此它们并不总是采用PNG格式,因此我无法承受使用另一个库进行全部转换的情况.

The script itself works perfectly, the image loads and can be manipulated and rendered and all. However, when I try to "compile" this script with py2exe, everything works but the JPEG image. Replacing it with a PNG equivalent works, but since my program downloads images from the web, they won't always be in PNG format and I can't afford converting them all with another library.

我发现\ qt \ plugins \ imageformats目录(它们分别称为qjpeg4.dll和qjpeg4d.dll)中的某些DLL提供了对QImage的JPEG图像支持以及其他图像格式.我认为我需要在可执行文件中以某种方式使用它们,但是我不知道如何使用.我试过简单地将它们复制到我的exe目录,没有运气.我已经尝试了此处指示,这些文件在setup.py脚本中作为data_files,但是没有运气(看起来它所做的只是将这些文件复制到exe的目录,因此无论如何手动复制它们都不会改变).

I've discovered that JPEG image support for QImage, along with other image formats, is provided by some DLLs in the \qt\plugins\imageformats directory (they're called qjpeg4.dll and qjpeg4d.dll). I think I need to use them somehow in my executable, but I don't know how. I've tried simply copying them to my exe directory, no luck. I've tried, as indicated here, to include those files as data_files in the setup.py script, but no luck (it looks like all it does is copying these files to the exe's directory, so it changes nothing from copying them manually anyway).

我肯定有少数使用PyQt和JPEG图像的应用程序,它们是如何做到的?这似乎是一件微不足道的任务,但我现在仍然坚持下去.

I'm sure there's a handful of applications out there using PyQt with JPEG images, how do they do it? It seemed like a trivial task but I'm stuck on it now.

另外,我希望我的应用程序是跨平台的(为什么还要用Python进行编码?),我希望在为OS X或OS X进行打包时,不会遇到此类打包问题(这不是唯一的问题) Linux.我可以吗?

Also, I want my app to be cross-platform (why else would I be coding in Python?), I hope I won't run into such packaging trouble (it's not the only one) when packaging for OS X or Linux. Will I?

推荐答案

在经历了数小时的相同问题后,我想分享适用于Windows Vista的解决方案: 使用python2.6

After hours of stumbling around with the same issue, I’d like to share the solution that worked for me on windows vista: using python2.6

将以下目录复制到py2exe生成的dist目录中:

copy the following directory into your dist directory generated by py2exe:

C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats

我只是将imageformats目录直接放到了dist目录中,而没有对qt.conf或类似的内容做任何进一步的修改.我还没有尝试过,但这可能也适用于声子.

I just dropped the imageformats directory directly into my dist directory, without any further modifications to qt.conf or anything like that. I haven’t tried it, but this may work for phonon as well.

这篇关于在py2exe编译的Python脚本中为QImage启用JPEG支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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