python pyinstaller打包exe报错的解决方法
今天用python使用pyinstaller打包exe出现错误
环境pyqt5+python3.632位
在导入pyqt5包之前加上如下代码
importsys importos ifhasattr(sys,'frozen'): os.environ['PATH']=sys._MEIPASS+";"+os.environ['PATH'] fromPyQt5.QtWidgetsimportQApplication,QMainWindow frompyqt_ui.MainWindowimportMainWin if__name__=='__main__': app=QApplication(sys.argv) mainWindow=QMainWindow() main_dialog=MainWin(mainWindow) mainWindow.show() sys.exit(app.exec_())
运行
pyinstaller-Fmain2.py INFO:PyInstaller:3.5 INFO:Python:3.6.4 INFO:Platform:Windows-7-6.1.7601-SP1 INFO:wroteE:\workspace\devTest\main2.spec INFO:UPXisnotavailable. INFO:ExtendingPYTHONPATHwithpaths ['E:\\workspace\\devTest','E:\\workspace\\devTest'] INFO:checkingAnalysis INFO:BuildingbecauseE:\workspace\devTest\main2.pychanged INFO:Initializingmoduledependencygraph... INFO:Initializingmodulegraphhooks... INFO:Analyzingbase_library.zip... INFO:runningAnalysisAnalysis-00.toc INFO:AddingMicrosoft.Windows.Common-Controlstodependentassembliesoffinalexecutable requiredbyd:\mytool\env\env36-32\scripts\python.exe INFO:Cachingmodulehooks... INFO:AnalyzingE:\workspace\devTest\main2.py INFO:Processingpre-findmodulepathhookdistutils INFO:distutils:retargetingtonon-venvdir'C:\\ProgramFiles(x86)\\Python36-32\\Lib\\distutils\\__init__.py' INFO:Processingpre-safeimportmodulehookwin32com INFO:Loadingmodulehooks... INFO:Loadingmodulehook"hook-encodings.py"... INFO:Loadingmodulehook"hook-pydoc.py"... INFO:Loadingmodulehook"hook-PyQt5.py"... WARNING:Hiddenimport"sip"notfound! INFO:Loadingmodulehook"hook-PyQt5.QtCore.py"... INFO:Loadingmodulehook"hook-PyQt5.QtGui.py"... INFO:Loadingmodulehook"hook-PyQt5.QtWidgets.py"... INFO:Loadingmodulehook"hook-pythoncom.py"... INFO:Loadingmodulehook"hook-pywintypes.py"... INFO:Loadingmodulehook"hook-win32com.py"... INFO:Loadingmodulehook"hook-xml.py"... INFO:LookingforctypesDLLs INFO:Analyzingrun-timehooks... INFO:Includingrun-timehook'pyi_rth_pyqt5.py' INFO:Includingrun-timehook'pyi_rth_win32comgenpy.py' INFO:Lookingfordynamiclibraries INFO:Lookingforeggs INFO:UsingPythonlibraryd:\mytool\env\env36-32\scripts\python36.dll INFO:Foundbindingredirects: [] INFO:WarningswrittentoE:\workspace\devTest\build\main2\warn-main2.txt INFO:Graphcross-referencewrittentoE:\workspace\devTest\build\main2\xref-main2.html INFO:checkingPYZ INFO:Buildingbecausetocchanged INFO:BuildingPYZ(ZlibArchive)E:\workspace\devTest\build\main2\PYZ-00.pyz INFO:BuildingPYZ(ZlibArchive)E:\workspace\devTest\build\main2\PYZ-00.pyzcompletedsuccessfully. INFO:checkingPKG INFO:Buildingbecausetocchanged INFO:BuildingPKG(CArchive)PKG-00.pkg WARNING:Onebinaryaddedwithtwointernalnames. WARNING:('libGLESv2.dll', 'D:\\mytool\\env\\env36-32\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll', 'BINARY') WARNING:wasplacedpreviouslyat WARNING:('PyQt5\\Qt\\bin\\libGLESv2.dll', 'D:\\mytool\\env\\env36-32\\lib\\site-packages\\PyQt5\\Qt\\bin\\libGLESv2.dll', 'BINARY') INFO:BuildingPKG(CArchive)PKG-00.pkgcompletedsuccessfully. INFO:Bootloaderd:\mytool\env\env36-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe INFO:checkingEXE INFO:Buildingbecausetocchanged INFO:BuildingEXEfromEXE-00.toc INFO:AppendingarchivetoEXEE:\workspace\devTest\dist\main2.exe INFO:BuildingEXEfromEXE-00.toccompletedsuccessfully.
打包成功
运行出现正常界面
注:为避免重复将main.py更改为main2.py了
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对毛票票的支持。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。