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中常用的各种数据库操作模块和连接实例
May 29 Python
Python数据类型详解(一)字符串
May 08 Python
python2.7的编码问题与解决方法
Oct 04 Python
对python中array.sum(axis=?)的用法介绍
Jun 28 Python
python3安装speech语音模块的方法
Dec 24 Python
python自定义函数实现一个数的三次方计算方法
Jan 20 Python
python打包exe开机自动启动的实例(windows)
Jun 28 Python
Django 自定义分页器的实现代码
Nov 24 Python
Python values()与itervalues()的用法详解
Nov 27 Python
Python tkinter常用操作代码实例
Jan 03 Python
python 数据库查询返回list或tuple实例
May 15 Python
python读取hdfs并返回dataframe教程
Jun 05 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
国内php原创论坛
2006/10/09 PHP
php生成excel列名超过26列大于Z时的解决方法
2014/12/29 PHP
Windows2003下php5.4安装配置教程(Apache2.4)
2016/06/30 PHP
PHP中使用OpenSSL生成证书及加密解密
2017/02/05 PHP
javascript 四则运算精度修正函数代码
2010/05/31 Javascript
jQuery超酷平面式时钟效果代码分享
2020/03/30 Javascript
js实现登录注册框手机号和验证码校验(前端部分)
2017/09/28 Javascript
Vue官方文档梳理之全局配置
2017/11/22 Javascript
浅谈Webpack 持久化缓存实践
2018/03/22 Javascript
2种在vue项目中使用百度地图的简单方法
2018/09/28 Javascript
详解关于表格合并span-method方法的补充(表格数据由后台动态返回)
2019/05/21 Javascript
JavaScript实现的联动菜单特效示例
2019/07/08 Javascript
JavaScript命令模式原理与用法实例详解
2020/03/10 Javascript
vue中el-input绑定键盘按键(按键修饰符)
2020/07/22 Javascript
基于JavaScript实现简单扫雷游戏
2021/01/02 Javascript
[01:21]DOTA2新纪元-7.0新版本即将开启!
2016/12/11 DOTA
Python实现的文本编辑器功能示例
2017/06/30 Python
利用标准库fractions模块让Python支持分数类型的方法详解
2017/08/11 Python
Numpy 改变数组维度的几种方法小结
2018/08/02 Python
深入理解Python中的 __new__ 和 __init__及区别介绍
2018/09/17 Python
对python遍历文件夹中的所有jpg文件的实例详解
2018/12/08 Python
python读取raw binary图片并提取统计信息的实例
2020/01/09 Python
使用Keras建立模型并训练等一系列操作方式
2020/07/02 Python
python用tkinter实现一个gui的翻译工具
2020/10/26 Python
纯CSS3实现鼠标滑过按钮动画第二节
2020/07/16 HTML / CSS
HTML5 Canvas的事件处理介绍
2015/04/24 HTML / CSS
跟单文员的岗位职责
2013/11/14 职场文书
晚会邀请函范文
2014/01/24 职场文书
综合实践教学反思
2014/01/31 职场文书
购房协议书范本
2014/04/11 职场文书
关于建议书的格式范文
2014/05/20 职场文书
购房协议书范本
2014/10/02 职场文书
无婚姻登记记录证明
2015/06/18 职场文书
2016年大学校运会广播稿件
2015/12/21 职场文书
小学五年级(说明文3篇)
2019/08/13 职场文书
Django框架模板用法详解
2022/06/10 Python