解决pyqt 打包成py2exe后在界面正常显示jpeg的问题
2015-10-20 09:42
666 查看
本来以为写好代码,直接使用py2exe打包后就一切大功告成,谁知道PyQt4中QPixmap.load图片后,只能正常显示PNG格式的图片(原来这个是QT默认支持的图片格式),加载
JPEG格式图片都返回QPixmap is NULL ,查了很多相关问题,试了解决方案,都不奏效,最后辛亏去翻了一下py2exe的论坛(http://www.py2exe.org/index.cgi/Py2exeAndPyQt),才恍然间把问题解决了!
py2exe原文如下:
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"))]
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\imageformatsto <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"))]
相关文章推荐
- QT中关闭应用程序和窗口的函数
- Qt捕捉窗口关闭事件与信号的捕捉
- 【SPOJ】QTREE 1 树链剖分裸题
- QT连接接Oracle数据库大盘点
- 在QThread中使用slots
- Qt: QT中PRO文件写法的详细介绍
- Qt:把QString转换为 double类型
- Qt:QT中PRO文件写法的详细介绍
- 字符串转换成金额的两种方式
- Qt学习之路(24): QPainter
- Qt Style Sheet实践(四):行文本编辑框QLineEdit及自动补全
- Qt Style Sheet实践(三):QCheckBox和QRadioButton
- Qt Style Sheet实践(二):组合框QComboBox的定制
- Qt Style Sheet实践(一):按钮及关联菜单
- Qt 无边框、透明、可移动、的个性窗体案例详解
- Qt之对话框设计——利用QPalette改变控件颜色
- QT Win7开发环境安装配置程
- Qt5窗口关闭与窗口销毁
- qtxlsx将excel中的数据读取到widget上
- qtxlsx读取excle的数据