作者博客地址:http://www.yooongchun.cn/
在用pyinstaller打包python程序
pyinstaller版本为:3.3.1
python 版本:3.6.1
系统版本:Windows-10-10.0.16299-SP0
我的python程序名为:data_processing_gui.py
程序在python环境下正常运行。
打包使用的格式为:pyinstaller -F -p <导入的包路径> myprogram.py
完整打包命令为:
pyinstaller -F -p C:UsersfanyuAnaconda3Lib;C:UsersfanyuAnaconda3Libsite-packages;C:UsersfanyuAnaconda3Libsite-packagesPyQt5Qtin;C:UsersfanyuAnaconda3Libsite-packagespydicom;C:UsersfanyuAnaconda3Libsite-packages
adiomics;C:UsersfanyuAnaconda3Libsite-packagespywt;C:UsersfanyuAnaconda3Libsite-packagespywt\_extensions;C:UsersfanyuAnaconda3Libsite-packages ensorflow;C:UsersfanyuAnaconda3Libsite-packagesSimpleITK;C:UsersfanyuAnaconda3Libsite-packagesPIL;C:UsersfanyuAnaconda3Libsite-packagespandas;C:UsersfanyuAnaconda3Libsite-packages
rrd;C:UsersfanyuAnaconda3Libsite-packages
umpy -i C:UsersfanyuDesktopworkpackageimagedoctor.ico data_processing_gui.py
pause
打包过程无报错,打包完成后运行程序提示出错信息:
Traceback (most recent call last):
File "data_processing_gui.py", line 12, in <module>
File "c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages
adiomics\__init__.py", line 15, in <module>
File "c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages
adiomicsimageoperations.py", line 6, in <module>
File "c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packagespywt\__init__.py", line 17, in <module>
File "c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packagespywt\_functions.py", line 17, in <module>
File "c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
File "pywt/_extensions/_pywt.pyx", line 1, in init pywt._extensions._pywt (pywt\_extensions\_pywt.c:31281)
ModuleNotFoundError: No module named 'pywt._extensions._cwt'
[7564] Failed to execute script data_processing_gui
最后在Stackoverflow上发现了一个类似问题,最终解决了问题
解决方案是:
首先,使用pyinstaller 打包生成".spec" 文件
hiddenimport=[]
部分添加缺少的module,我的程序中缺少的是 pywt
模块,因而添加:
接下来,使用文本编辑器打开".spec"文件,在 hiddenimport=[
"pywt","pywt._extensions._cwt"]
然后使用pyinstaller
生成新的exe程序:
pyinstaller my.spec
最终,问题解决。
这里有Stackoverflow 上我的问题:https://stackoverflow.com/questions/49232117/using-pyinstaller-to-package-python-program-and-there-is-a-nomodulefinderror/49289859#49289859
这里是找到答案的位置:https://stackoverflow.com/questions/47607315/modulenotfounderror-no-module-named-pandas-libs-tslibs-timedeltas