PyQt 应用程序:使用 py2exe 编译后不显示 gif 文件

发布于 2024-10-15 04:51:53 字数 409 浏览 5 评论 0原文

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

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

似乎什么都不起作用——我到底做错了什么?

For some reason on my system (Windows XP 32-bit, Python 2.6) PyQt is able to display gifs perfectly when run in the python interpreter, but when I run it through py2exe, they no longer display.

I've tried everything I've googled: copying the gif DLLs from PyQt into an imageformats/ folder, setting up a qt.conf (as another stackoverflow thread suggested), done a setLibraryPaths to where the imageformat DLLs were, copied the setup file from http://wiki.wxpython.org/py2exe-python26 .

Nothing seems to work -- what on earth could I be doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨夜星沙 2024-10-22 04:51:53

我不确定你是如何用 py2exe 编译 PyQt 的;我没有成功,并切换到 pyinstaller
Py2exe 与 PyQt 合作不佳,并且拒绝根据所具有的小部件进行编译。

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

I'm not sure how you even managed to compile PyQt with py2exe; I had no success, and switched to pyinstaller.
Py2exe wasn't cooperating well PyQt and refused to compile depending on what widgets were featured.

I'd recommend switching to pyinstaller for compiling PyQt; see if it allows what you want in this case

指尖上的星空 2024-10-22 04:51:53
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)
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)
小草泠泠 2024-10-22 04:51:53

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

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

对于 dll 文件,您需要在 setup.py 文件中进行设置:

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

Just in case anyone is in this situation, I found the solution. These is what you need to do when compiling with py2exe so your image files are shown:

  • All the image files (gif, png, jpg) need to be copied to the dist folder
  • Qt dll files need to be copied from Qt installation folder to
    dist\imageformats

For the dll files you need to set this on your setup.py file:

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'
                ])],
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文