解决Pyinstaller打包软件失败的一个坑
最近写了一个软件屡屡打包不能正常运行,而直接在cmd命令行窗口运行却都能正常输出,没有任何报错,一开始怀疑程序里面sys.args[1]使用不对,找了很久发现importnumpy才是导致代码不能打包的直接原因。
不知道为何引用这个包就不能正常打包成exe了。
程序编译中出错的代码如下
pyinstaller-FC:\Users\LHD_PC\AppData\Local\Progr ams\Python\Python38-32\Scripts\AutoElecCalcE.py 91INFO:PyInstaller:3.6 91INFO:Python:3.8.0 93INFO:Platform:Windows-10-10.0.17134-SP0 94INFO:wroteC:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\AutoElecCalcE.spec 99INFO:UPXisnotavailable. 101INFO:ExtendingPYTHONPATHwithpaths [‘C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts', ‘C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts'] 101INFO:checkingAnalysis 113INFO:BuildingbecauseC:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\AutoElecCalcE.pychanged 113INFO:Initializingmoduledependencygraph… 119INFO:Cachingmodulegraphhooks… 134INFO:Analyzingbase_library.zip… 5521INFO:Cachingmoduledependencygraph… 5650INFO:runningAnalysisAnalysis-00.toc 5654INFO:AddingMicrosoft.Windows.Common-Controlstodependentassembliesoffinalexecutable requiredbyc:\users\lhd_pc\appdata\local\programs\python\python38-32\python.exe 6018INFO:AnalyzingC:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\AutoElecCalcE.py 6547INFO:Processingpre-findmodulepathhookdistutils 6549INFO:distutils:retargetingtonon-venvdir‘c:\users\lhd_pc\appdata\local\programs\python\python38-32\lib' 7356INFO:Processingpre-findmodulepathhooksite 7357INFO:site:retargetingtofake-dir‘c:\users\lhd_pc\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\fake-modules' 8994INFO:Processingpre-safeimportmodulehooksetuptools.extern.six.moves 12451INFO:Processingmodulehooks… 12451INFO:Loadingmodulehook“hook-distutils.py”… 12454INFO:Loadingmodulehook“hook-encodings.py”… 12744INFO:Loadingmodulehook“hook-lib2to3.py”… 12757INFO:Loadingmodulehook“hook-numpy.core.py”… 13540INFO:Loadingmodulehook“hook-numpy.py”… 13546INFO:Loadingmodulehook“hook-pkg_resources.py”… 15200INFO:Processingpre-safeimportmodulehookwin32com 15767INFO:Excludingimport‘main' 15769INFO:Removingimportofmainfrommodulepkg_resources 15769INFO:Loadingmodulehook“hook-pydoc.py”… 15782INFO:Loadingmodulehook“hook-pythoncom.py”… 16198INFO:Loadingmodulehook“hook-pywintypes.py”… 16605INFO:Loadingmodulehook“hook-scipy.py”… 16663INFO:Loadingmodulehook“hook-setuptools.py”… 18364INFO:Loadingmodulehook“hook-sysconfig.py”… 18375INFO:Loadingmodulehook“hook-win32com.py”… c:\users\lhd_pc\appdata\local\programs\python\python38-32\lib\site-packages\win32com\client\makepy.py:369:SyntaxWarning:“isnot”withaliteral.Didyoumean“!=”? ifpathisnot‘'andnotos.path.exists(path): 20023INFO:Loadingmodulehook“hook-xml.dom.domreg.py”… 20030INFO:Loadingmodulehook“hook-xml.py”… 20090INFO:LookingforctypesDLLs 20132INFO:Analyzingrun-timehooks… 20139INFO:Includingrun-timehook‘pyi_rth_multiprocessing.py' 20162INFO:Includingrun-timehook‘pyi_rth_pkgres.py' 20192INFO:Includingrun-timehook‘pyi_rth_win32comgenpy.py' 20229INFO:Lookingfordynamiclibraries 21772INFO:Lookingforeggs 21772INFO:UsingPythonlibraryc:\users\lhd_pc\appdata\local\programs\python\python38-32\python38.dll 21773INFO:Foundbindingredirects: [] 21798INFO:WarningswrittentoC:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\build\AutoElecCalcE\warn-AutoElecCalcE.txt 21932INFO:Graphcross-referencewrittentoC:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\build\AutoElecCalcE\xref-AutoElecCalcE.html 22003INFO:checkingPYZ 22017INFO:Buildingbecausetocchanged 22017INFO:BuildingPYZ(ZlibArchive)C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\build\AutoElecCalcE\PYZ-00.pyz 23373INFO:BuildingPYZ(ZlibArchive)C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\build\AutoElecCalcE\PYZ-00.pyzcompletedsuccessfully. 23419INFO:checkingPKG 23427INFO:Buildingbecausetocchanged 23427INFO:BuildingPKG(CArchive)PKG-00.pkg 37085INFO:BuildingPKG(CArchive)PKG-00.pkgcompletedsuccessfully. 37098INFO:Bootloaderc:\users\lhd_pc\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe 37098INFO:checkingEXE 37107INFO:RebuildingEXE-00.tocbecauseAutoElecCalcE.exemissing 37107INFO:BuildingEXEfromEXE-00.toc 37111INFO:AppendingarchivetoEXEC:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\dist\AutoElecCalcE.exe 37154INFO:BuildingEXEfromEXE-00.toccompletedsuccessfully.
之前一直怀疑路径没处理对,后面看了很多别的代码发现也没问题,突发奇想是不是某个包造成不能正常压缩的,然后写了个测试文件,一行行注释掉引用的包后,发现只要注释掉了numpy便可以正常压缩成exe文件了。
补充:pyinstaller安装失败的解决办法
pyinstaller是一个很好用的将python文件打包成不依赖python环境的exe的库,但是在cmd中使用“pipinstallpyinstaller”时,总会出现很多奇奇怪怪的问题。
我在安装库的过程中,碰到了下载之后,直接开始安装就报错退出安装的问题。
解决办法如下
1.其实一点也不麻烦
2.先“pipinstallpywin32”
3.在“pipinstallwheel”
4.试一下“pipinstallpyinstaller”
以上为个人经验,希望能给大家一个参考,也希望大家多多支持毛票票。如有错误或未考虑完全的地方,望不吝赐教。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。