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

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!

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值