您的位置:首页 > 编程语言 > Qt开发

使用PyInstaller把PyQt5生产exe时文件报错总结

2018-03-14 17:12 239 查看

PyInstaller使PyQt5生成exe执行文件

本文主要总结了PyInstaller使用过程中遇到的问题及解决办法

PyInstaller简介

PyInstaller 是一个用来将 Python 程序打包成一个独立可执行软件包,支持 Windows、Linux 和 Mac OS X。。 —— [ PyInstaller官网 ]

PyInstaller打包PyQt的详细方法可参照使用pyinstaller打包Python3.5+PyQt5.6项目生成exe文件进行安装

运行报错汇总

1. pyinstaller : AttributeError: module ‘enum’ has no attribute ‘IntFlag’

这个问题主要是enum34包的问题,Stack Overflow上说在pythonb3.4以后就有了标准的enum包,把enum卸载即可。但我的程序中需要tensorflow,而我的版本是1.4,明确要求需要依赖enum34这个包,还不能删除。

今天早上看无意发现tensorflow已经更新到了tensorflow-1.7

=====================================



=====================================

我一看依赖已经不需要enum34了,赶紧更新

#本来应该是直接更新
pip install -U tensorflow

#但是我为了彻底除去enum,所以我是先卸载,再安装具体如下
pip uninstall tensorflow

pip install tensorflow


更新后,再执行Pyinstaller,就没有再报这个错误。

2.pyinstaller ‘utf-8’ codec can’t decode byte 0xce in position 82:

这个问题遇到时比较头疼,因为Python好多次都遇到编码问题,而且感觉不太好解决

经过多次搜索以及实验,最后参考了这篇文章Stack Overflow并修改,并成功

就是把Python\Lib\site-packages\Pyinstaller\compat.py 这个文件,找到 out = out.decode(encoding)这句话,

out = out.decode(encoding)
修改为
out = out.decode(encoding, errors='ignore')


这样执行就不再报这个错了。

3.This application failed to start because it could not find or load the Qt platform plugin “windows” in “”.

然后运行

pyinstaller calc.py


又看到报错信息

This application failed to start because it could not find or load the Qt platform plugin
"windows" in "".


然后查询发现缺少配置文件,需要把Qt安装目录中plugins下的platforms文件夹,一并粘贴到exe文件所在的文件夹,再次运行exe文件,就不会报错了参考

4.QPixmap::scaled: Pixmap is a null pixmap.

我的PyQt5程序中,有一个加载图片并显示的功能,在执行py文件时,Qt界面可以正常加载;但是转为exe后,用exe文件打开,就不显示,会报错。

经过查询QPixmap is null on other machines,还是缺少配置文件,最后找到Qt的plugins/imageformats文件夹,把imageformats文件夹复制到exe相同文件夹下,就可以正常执行了。

最后文件完美执行,感谢Stack Overflow!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: