【问题标题】:PyQt app: gif files don't show after compiling with py2exePyQt 应用程序:使用 py2exe 编译后不显示 gif 文件
【发布时间】:2011-01-31 04:51:18
【问题描述】:

由于某种原因,在我的系统(Windows XP 32 位,Python 2.6)上,PyQt 在 python 解释器中运行时能够完美显示 gif,但是当我通过 py2exe 运行它时,它们不再显示。

我已经尝试了所有我在谷歌上搜索过的东西:将 gif DLL 从 PyQt 复制到 imageformats/ 文件夹中,设置 qt.conf(正如另一个 stackoverflow 线程建议的那样),将 setLibraryPaths 设置到 imageformat DLL 所在的位置,复制来自http://wiki.wxpython.org/py2exe-python26 的设置文件。

似乎没有任何效果——我到底做错了什么?

【问题讨论】:

  • 将 gif(s) 转换为 png(s) 并在您的应用程序中使用 pngs 而不是 gifs。我遇到了同样的问题,但无法探索问题的原因。改用 pngs 为我解决了这个问题。 HTH。
  • 你可能想看看这个试图解决 jpeg 问题的现有问题:stackoverflow.com/questions/885906/…

标签: python qt pyqt py2exe


【解决方案1】:

我不确定你是如何设法用 py2exe 编译 PyQt 的;我没有成功,并切换到pyinstaller
Py2exe 不能很好地配合 PyQt 并拒绝根据所提供的小部件进行编译。

我建议切换到 pyinstaller 来编译 PyQt;看看在这种情况下它是否允许你想要的东西

【讨论】:

  • 有时使用编译器有点令人生畏;需要时寻求帮助
  • 在我切换到 pyinstaller 之前,我在过去使用 py2exe 和 pyqt 时没有遇到任何问题。猜你运气不好:-/
  • 这肯定是某种阴谋:/
【解决方案2】:
from distutils.core import setup
import py2exe

DATA=[('imageformats',['C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qjpeg4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qgif4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qico4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qmng4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qsvg4.dll',
    'C:\\Python26/Lib/site-packages/PyQt4/plugins/imageformats/qtiff4.dll'
    ])]
setup(windows=[{"script":"your_python_script.py"}], 
    data_files = DATA,
    options={"py2exe":{
        "includes":["sip", "PyQt4.QtNetwork", "PyQt4.QtWebKit", "PyQt4.QtSvg" ],
        "bundle_files":3,
        "compressed":True,
        "xref":True}}, 
    zipfile=None)

【讨论】:

    【解决方案3】:

    以防万一有人遇到这种情况,我找到了解决方案。使用 py2exe 编译时需要执行以下操作,以便显示图像文件:

    • 需要将所有图片文件(gif、png、jpg)复制到 dist 文件夹中
    • Qt dll 文件需要从 Qt 安装文件夹复制到 dist\imageformats

    对于需要在 setup.py 文件中设置的 dll 文件:

    windows = [{
                "script":"yourPythonScript.py",
                "icon_resources": [(1, "nameOfIcoFile.ico")],
                "dest_base":"nameOfExeFile"
                }],
                data_files = [
                    ('imageformats',
                    [r'C:\Python27\Lib\site-packages\PyQt4\plugins\imageformats\qico4.dll',
                    r'C:\Python27\Lib\site-packages\PyQt4\plugins\imageformats\qgif4.dll'
                    ])],
    )
    

    【讨论】:

      猜你喜欢
      • 2018-04-26
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 2010-12-06
      • 1970-01-01
      相关资源
      最近更新 更多