解决pyinstaller打包sklearn等库出现的问题: 提示failed to execute script xxx

pyinstaller安装,简单打包可以参考:https://blog.csdn.net/qq_40587575/article/details/85076934

-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 

pyinstaller [参数] [要打包的程序.py]

参数说明:
–icon=图标路径
-F 打包成一个exe文件
-w 使用窗口,无控制台
-c 使用控制台,无窗口
-D 创建一个目录,里面包含exe以及其他一些依赖性文件
pyinstaller -h 来查看参数

重点:

刚开始进行编译的时候,切忌直接使用:  pyinstaller -F -w demo.py

应该使用:pyinstaller -F -c demo.py 此时打包完成后,点击exe执行文件,如果有报错的话,将在控制台显示。这是,要做好截图的准备,因为控制台报错后是一闪而过的。

 

 报错信息: No module named 'typedefs'

 此时,我们可以看到 importError 的报错信息,  由于此时找不到typedefs模块,所以程序直接报 Failed to excute script xxxx

删除原来的dist、build 文件, spec文件, 在编译的时候加上: 

pyinstaller -F -c QTimerTest.py --hidden-import sklearn.neighbors.typedefs

或者

直接在. spec 文件里的 hiddenimports = [ ] 增加: 如最后的代码

报错信息: No module named 'sklearn.neighbors.quad_tree'

 报错信息: No module named 'pywt._extendions._cwt' 

汇总上述的问题可以使用命令:

pyinstaller -F -c QTimerTest.py --hidden-import sklearn.neighbors.typedefs --hidden-import sklearn.neighbors.quad_tree --hidden-import pywt._extensions._cwt --add-data=xgboost;xgboost

程序如果还是会报错的话, 可以使用相同的方法找出原因,有原因一般就好找答案了。。。。。。。。。。。

参考:
 

1. XGBoost出现的问题解决办法:
https://my.oschina.net/u/1241965/blog/2997992

2.pywt小波包库解决方法:
https://stackoverflow.com/questions/41998403/pyinstaller-importerror-on-pywt-ctw-module

3.sklearn解决方法:
https://www.smwenku.com/a/5b86bb8a2b71775d1cd5c2d8/zh-cn/

https://stackoverflow.com/questions/31774906/why-do-i-get-an-importerror-when-building-a-exe-with-pyinstaller

http://www.voidcn.com/article/p-nqtjgive-bms.html

在pyinstaller生成的 .spec文件中修改为:

主要是hiddenimportts  主要都是这一块出问题,pyinstaller找不到库在哪里
 

 # -*- mode: python -*-
 
block_cipher = None
 
 
a = Analysis(['MyPythonApplication.py'],
             pathex=['..\\ApplicationFolder'],
             binaries=[],
             datas=[],
             hiddenimports=['cython', 'sklearn', 'sklearn.ensemble', 'sklearn.neighbors.typedefs', 'sklearn.neighbors.quad_tree', 'sklearn.tree._utils'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='ExeFileName',             
          debug=False,
          strip=False,
          upx=False,
          console=False )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='ApplicationName')

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值