解决pyqt 打包成py2exe后在界面正常显示jpeg的问题
来源:互联网 发布:电子数据调查分析师 编辑:程序博客网 时间:2024/05/22 17:45
本来以为写好代码,直接使用py2exe打包后就一切大功告成,谁知道PyQt4中QPixmap.load图片后,只能正常显示PNG格式的图片(原来这个是QT默认支持的图片格式),加载
JPEG格式图片都返回QPixmap is NULL ,查了很多相关问题,试了解决方案,都不奏效,最后辛亏去翻了一下py2exe的论坛(http://www.py2exe.org/index.cgi/Py2exeAndPyQt),才恍然间把问题解决了!
py2exe原文如下:
PyQt4 and image loading (JPG, GIF, etc)
PyQt4 uses plugins to read those image formats, so you'll need to copy the folder PyQt4\plugins\imageformats to <appdir>\imageformats. Like in the above cases, you can use data_files for this. This won't work with bundle_files on.
If the plugins are not reachable, then QPixmap.load/loadFromData will return False when loading an image in those formats.
This will work with bundle_files as well, but you need to exclude the Qt DLLs from bundle (using the dll_excludes option) and add them to the directory with the executable through some other mechanism (such as data_files).
如果只是像网上其他说的直接“PyQt4\plugins\imageformats to <appdir>\imageformats”,那还是没有效果的,所以bundle_files 一项至关重要(This won't work with bundle_files on. 一定要注意这句话)。
bundle_files :bundle dlls in the zipfile or the exe. Valid values for bundle_files are: 3 = don't bundle (default) 2 =everything but the Python interpreter 1 = bundle everything, including the Python interpreter
所以我的解决方案,只需两步:
1. py2exe_options 中"bundle_files": 3
2. setup 中 data_files = [("imageformats",glob.glob("E:\Program Files (x86)\Python27\Lib\site-packages\PyQt4\plugins\imageformats\*.dll"))]
- 解决pyqt 打包成py2exe后在界面正常显示jpeg的问题
- py2exe 打包 pyqt程序的图片不显示的问题
- PyQt4 QPixmap.load/loadFromData 使用py2exe 打包后无法显示JPEG,gif等图片的问题
- py2exe 打包 pyqt程序的图片(ico等) 不显示的问题
- Unity Shader 在UnityEditor中显示正常,打包后不显示的问题
- pyqt 用py2exe打包出错的解决办法
- py2exe打包pyqt程序
- PyQt 图标问题 ,cx_Freeze 打包后图标无法显示
- Py2exe 打包后图标不显示
- Py2exe 打包后图标不显示
- py2exe打包,vista/win7下图标显示问题的解决方案
- py2exe打包,vista/win7下图标显示问题的解决方案
- 在Linux下键入命令service network restart后界面显示一半为乱码一半正常的问题
- py2exe 打包 PyQt4 的问题
- python(py2exe)打包成exe执行文件,vista/win7下icon图标显示问题的解决方案
- twisted(iocp)程序在用py2exe打包时的问题
- py2exe打包在Windows7上的图标问题
- 解决 py2exe打包后,总是多显示一个DOS黑色窗口
- 几种用OD脱壳方法
- Eclipse一飘而过的解决办法
- JAVA - IO流 - 整理
- 使用c3p0与DBCP连接池,造成的MySql 8小时问题解决方案
- iOS开发之UITextField常用属性设置
- 解决pyqt 打包成py2exe后在界面正常显示jpeg的问题
- 前端之路有险阻,少年需努力
- SQL SERVER 权限所有链接
- 对stdin,stdout 和STDOUT_FILENO,STDIN_FILENO的学习
- Android SnackBar
- OpenGL开发之旅基础知识介绍
- 自信的源泉
- Study JQuery《data的实现方式》
- Sublime Text里的一些快捷操作