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

查看:36
本文介绍了在 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 等效文件替换它是可行的,但由于我的程序从 Web 下载图像,它们不会总是采用 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.

我发现对 QImage 以及其他图像格式的 JPEG 图像支持是由 qtpluginsimageformats 目录中的一些 DLL 提供的(它们被称为 qjpeg4.dll 和 qjpeg4d.dll).我想我需要在我的可执行文件中以某种方式使用它们,但我不知道如何使用.我试过简单地将它们复制到我的 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 qtpluginsimageformats 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 或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:Python26Libsite-packagesPyQt4pluginsimageformats

我只是将 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天全站免登陆