python pyinstaller 打包exe报错

回眸只為那壹抹淺笑 提交于 2020-04-06 11:36:35

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


 

 

环境pyqt5 + python3.6 32位

 

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

import sysimport osif hasattr(sys, 'frozen'):    os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH']from PyQt5.QtWidgets import QApplication, QMainWindowfrom pyqt_ui.MainWindow import MainWinif __name__ == '__main__':    app = QApplication(sys.argv)    mainWindow = QMainWindow()    main_dialog = MainWin(mainWindow)    mainWindow.show()    sys.exit(app.exec_())

运行

pyinstaller -F main2.py

96 INFO: PyInstaller: 3.5
97 INFO: Python: 3.6.4
97 INFO: Platform: Windows-7-6.1.7601-SP1
98 INFO: wrote E:\workspace\devTest\main2.spec
100 INFO: UPX is not available.
101 INFO: Extending PYTHONPATH with paths
['E:\\workspace\\devTest', 'E:\\workspace\\devTest']
101 INFO: checking Analysis
104 INFO: Building because E:\workspace\devTest\main2.py changed
104 INFO: Initializing module dependency graph...
107 INFO: Initializing module graph hooks...
109 INFO: Analyzing base_library.zip ...
4264 INFO: running Analysis Analysis-00.toc
4291 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by d:\mytool\env\env36-32\scripts\python.exe
4632 INFO: Caching module hooks...
4642 INFO: Analyzing E:\workspace\devTest\main2.py
4771 INFO: Processing pre-find module path hook distutils
4772 INFO: distutils: retargeting to non-venv dir 'C:\\Program Files (x86)\\Python36-32\\Lib\\distutils\\__init__.py'
4773 INFO: Processing pre-safe import module hook win32com
5572 INFO: Loading module hooks...
5572 INFO: Loading module hook "hook-encodings.py"...
5669 INFO: Loading module hook "hook-pydoc.py"...
5670 INFO: Loading module hook "hook-PyQt5.py"...
5804 WARNING: Hidden import "sip" not found!
5805 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
5900 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
6088 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
6463 INFO: Loading module hook "hook-pythoncom.py"...
6855 INFO: Loading module hook "hook-pywintypes.py"...
7235 INFO: Loading module hook "hook-win32com.py"...
7320 INFO: Loading module hook "hook-xml.py"...
7666 INFO: Looking for ctypes DLLs
7667 INFO: Analyzing run-time hooks ...
7670 INFO: Including run-time hook 'pyi_rth_pyqt5.py'
7672 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
7679 INFO: Looking for dynamic libraries
8747 INFO: Looking for eggs
8747 INFO: Using Python library d:\mytool\env\env36-32\scripts\python36.dll
8747 INFO: Found binding redirects:
[]
8752 INFO: Warnings written to E:\workspace\devTest\build\main2\warn-main2.txt
8822 INFO: Graph cross-reference written to E:\workspace\devTest\build\main2\xref-main2.html
8837 INFO: checking PYZ
8839 INFO: Building because toc changed
8839 INFO: Building PYZ (ZlibArchive) E:\workspace\devTest\build\main2\PYZ-00.pyz
9775 INFO: Building PYZ (ZlibArchive) E:\workspace\devTest\build\main2\PYZ-00.pyz completed successfully.
9788 INFO: checking PKG
9789 INFO: Building because toc changed
9790 INFO: Building PKG (CArchive) PKG-00.pkg
10019 WARNING: One binary added with two internal names.
10020 WARNING: ('libGLESv2.dll',
'D:\\mytool\\env\\env36-32\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
'BINARY')
10020 WARNING: was placed previously at
10021 WARNING: ('PyQt5\\Qt\\bin\\libGLESv2.dll',
'D:\\mytool\\env\\env36-32\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll',
'BINARY')
20621 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
20628 INFO: Bootloader d:\mytool\env\env36-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
20628 INFO: checking EXE
20631 INFO: Building because toc changed
20631 INFO: Building EXE from EXE-00.toc
20632 INFO: Appending archive to EXE E:\workspace\devTest\dist\main2.exe
20659 INFO: Building EXE from EXE-00.toc completed successfully.

打包成功

运行出现正常界面

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!