python pyinstaller打包exe报错的解决方法


Posted in Python onNovember 02, 2019

今天用python 使用pyinstaller打包exe出现错误

python pyinstaller打包exe报错的解决方法

环境pyqt5 + python3.6 32位

在导入pyqt5包之前加上如下代码

import sys
import os
if hasattr(sys, 'frozen'):
 os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH']

from PyQt5.QtWidgets import QApplication, QMainWindow
from pyqt_ui.MainWindow import MainWin

if __name__ == '__main__':
 app = QApplication(sys.argv)
 mainWindow = QMainWindow()
 main_dialog = MainWin(mainWindow)
 mainWindow.show()
 sys.exit(app.exec_())

运行

pyinstaller -F main2.py
INFO: PyInstaller: 3.5
INFO: Python: 3.6.4
INFO: Platform: Windows-7-6.1.7601-SP1
INFO: wrote E:\workspace\devTest\main2.spec
INFO: UPX is not available.
INFO: Extending PYTHONPATH with paths
['E:\\workspace\\devTest', 'E:\\workspace\\devTest']
INFO: checking Analysis
INFO: Building because E:\workspace\devTest\main2.py changed
INFO: Initializing module dependency graph...
INFO: Initializing module graph hooks...
INFO: Analyzing base_library.zip ...
INFO: running Analysis Analysis-00.toc
INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
 required by d:\mytool\env\env36-32\scripts\python.exe
INFO: Caching module hooks...
INFO: Analyzing E:\workspace\devTest\main2.py
INFO: Processing pre-find module path hook distutils
INFO: distutils: retargeting to non-venv dir 'C:\\Program Files (x86)\\Python36-32\\Lib\\distutils\\__init__.py'
INFO: Processing pre-safe import module hook win32com
INFO: Loading module hooks...
INFO: Loading module hook "hook-encodings.py"...
INFO: Loading module hook "hook-pydoc.py"...
INFO: Loading module hook "hook-PyQt5.py"...
WARNING: Hidden import "sip" not found!
INFO: Loading module hook "hook-PyQt5.QtCore.py"...
INFO: Loading module hook "hook-PyQt5.QtGui.py"...
INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
INFO: Loading module hook "hook-pythoncom.py"...
INFO: Loading module hook "hook-pywintypes.py"...
INFO: Loading module hook "hook-win32com.py"...
INFO: Loading module hook "hook-xml.py"...
INFO: Looking for ctypes DLLs
INFO: Analyzing run-time hooks ...
INFO: Including run-time hook 'pyi_rth_pyqt5.py'
INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
INFO: Looking for dynamic libraries
INFO: Looking for eggs
INFO: Using Python library d:\mytool\env\env36-32\scripts\python36.dll
INFO: Found binding redirects:
[]
INFO: Warnings written to E:\workspace\devTest\build\main2\warn-main2.txt
INFO: Graph cross-reference written to E:\workspace\devTest\build\main2\xref-main2.html
INFO: checking PYZ
INFO: Building because toc changed
INFO: Building PYZ (ZlibArchive) E:\workspace\devTest\build\main2\PYZ-00.pyz
INFO: Building PYZ (ZlibArchive) E:\workspace\devTest\build\main2\PYZ-00.pyz completed successfully.
INFO: checking PKG
INFO: Building because toc changed
INFO: Building PKG (CArchive) PKG-00.pkg
WARNING: One binary added with two internal names.
WARNING: ('libGLESv2.dll',
 'D:\\mytool\\env\\env36-32\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
 'BINARY')
WARNING: was placed previously at
WARNING: ('PyQt5\\Qt\\bin\\libGLESv2.dll',
 'D:\\mytool\\env\\env36-32\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
 'BINARY')
INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
INFO: Bootloader d:\mytool\env\env36-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
INFO: checking EXE
INFO: Building because toc changed
INFO: Building EXE from EXE-00.toc
INFO: Appending archive to EXE E:\workspace\devTest\dist\main2.exe
INFO: Building EXE from EXE-00.toc completed successfully.

打包成功

运行出现正常界面

注:为避免重复将main.py 更改为main2.py了

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对三水点靠木的支持。

Python 相关文章推荐
python实现数值积分的Simpson方法实例分析
Jun 05 Python
Python实现简单拆分PDF文件的方法
Jul 30 Python
python 与GO中操作slice,list的方式实例代码
Mar 20 Python
老生常谈Python startswith()函数与endswith函数
Sep 08 Python
运行django项目指定IP和端口的方法
May 14 Python
让代码变得更易维护的7个Python库
Oct 09 Python
Python实现的删除重复文件或图片功能示例【去重】
Apr 23 Python
Python破解BiliBili滑块验证码的思路详解(完美避开人机识别)
Feb 17 Python
python numpy矩阵信息说明,shape,size,dtype
May 22 Python
10个示例带你掌握python中的元组
Nov 23 Python
Python破解极验滑动验证码详细步骤
May 21 Python
python中Matplotlib绘制直线的实例代码
Jul 04 Python
python自动生成model文件过程详解
Nov 02 #Python
python__name__原理及用法详解
Nov 02 #Python
简单了解python中的f.b.u.r函数
Nov 02 #Python
如何在python中实现随机选择
Nov 02 #Python
图解python全局变量与局部变量相关知识
Nov 02 #Python
Python如何实现动态数组
Nov 02 #Python
python基于gevent实现并发下载器代码实例
Nov 01 #Python
You might like
建立动态的WML站点(二)
2006/10/09 PHP
DISCUZ在win2003环境下 Unable to access ./include/common.inc.php in... 的问题终极解决方案
2011/11/21 PHP
phpstorm编辑器乱码问题解决
2014/12/01 PHP
彪哥1.1(智能表格)提供下载
2006/09/07 Javascript
utf8的编码算法 转载
2006/12/27 Javascript
javascript FormatNumber函数实现方法
2008/12/30 Javascript
jQuery 处理网页内容的实现代码
2010/02/15 Javascript
JS实现字体选色板实例代码
2013/11/20 Javascript
Jquery实现的一种常用高亮效果示例代码
2014/01/28 Javascript
jquerymobile局部渲染的各种刷新方法小结
2014/03/05 Javascript
JQuery中使用.each()遍历元素学习笔记
2014/11/08 Javascript
JavaScript日期类型的一些用法介绍
2015/03/02 Javascript
Nodejs中的this详解
2016/03/26 NodeJs
JavaScript实现Java中Map容器的方法
2016/10/09 Javascript
在vue中使用公共过滤器filter的方法
2018/06/26 Javascript
iview实现select tree树形下拉框的示例代码
2018/12/21 Javascript
微信小程序的注册页面包含倒计时验证码、获取用户信息
2019/05/22 Javascript
python将txt文件读取为字典的示例
2018/12/22 Python
window环境pip切换国内源(pip安装异常缓慢的问题)
2019/12/31 Python
Python 实现训练集、测试集随机划分
2020/01/08 Python
PyQt5+python3+pycharm开发环境配置教程
2020/03/24 Python
python实现简单猜单词游戏
2020/12/24 Python
深入浅出CSS3 background-clip,background-origin和border-image教程
2011/01/27 HTML / CSS
css3的transition效果和transfor效果示例介绍
2013/10/30 HTML / CSS
CSS3 :default伪类选择器使用简介
2018/03/15 HTML / CSS
HTML5新特性之语义化标签
2017/10/31 HTML / CSS
Canvas制作旋转的太极的示例
2018/03/09 HTML / CSS
西班牙汉普顿小姐:购买帆布鞋和太阳镜
2016/10/23 全球购物
eBay澳大利亚站:eBay.com.au
2018/02/02 全球购物
综合素质的自我鉴定
2013/10/07 职场文书
本科毕业生的求职信范文
2013/11/20 职场文书
销售人员职业生涯规划范文
2014/03/01 职场文书
补充协议书范本
2014/04/23 职场文书
2015年监理个人工作总结
2015/05/23 职场文书
感恩教育主题班会
2015/08/12 职场文书
小学数学继续教育研修日志
2015/11/13 职场文书