pyinstaller打包含xgboost的.py脚本 报错xgboost.libpath.XGBoostLibraryNotFound: Cannot find XGBoost Library...

任务:打包含xgboost模型的脚本为exe文件

command line:  pyinstaller -F filename.py

error 1.

error: maximum recurstion limits exceeded

solution: 打开spec文件, 在开头加上

import sys

sys.setrecursionlimit(1000000)

另外,在改debug=True  这样方便后面看报错信息。

再次运行: pyinstaller -F filename.spec

error2. 

从dist里把exe文件copy到目标文件夹里,结果报错:提示找不到xgboost library

pic1. error2

solution: 去提示的路径下  (site-packages\xgboost)看看,有没有xgboost.dll文件,是有的。于是在这里耗费了大量时间找问题。。。

终极解决方案:是xgboost hook问题https://github.com/pyinstaller/pyinstaller/pull/4077/commits/a11e82681b697b36b2690ffa8365acd130b8885d

在spec文件中更改binaries,datas, hiddenimports三个参数

from PyInstaller.utils.hooks import collect_submodules

from PyInstaller.utils.hooks import collect_data_files

data = collect_data_files('xgboost')

a = Analysis(['filename.py'],

            pathex=['filepath\\scripts'],

            binaries = data,

           datas = data,

            hiddenimports= collect_submodules('xgboost'),

            hookspath=[],

            runtime_hooks=[],

            excludes=[],

            win_no_prefer_redirects=False,

            win_private_assemblies=False,

            cipher=block_cipher,

            noarchive=False)


解决。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容