pyinstaller打包含有pickle.loads语句的程序时出错

kingsser16 2021-02-01 12:36:43
目标:
在fortran中调用python的随机森林模型进行预测


事情经过:
本人使用sklearn包中的ensemble随机森林训练了模型,用pickle.loads调用模型进行预测,程序编写无误后使用pyinstaller打包
预测程序中仅使用以下额外包
import numpy as np
import datetime
import pickle

使用
pyinstaller -F temp0201.py

打包,打包之后运行exe,提示No module named 'sklearn',便使用
pyinstaller -F temp0201.py --hidden-import sklearn

进行打包,运行exe提示No module named 'sklearn.ensemble.forest',便使用
pyinstaller -F temp0201.py --hidden-import sklearn.ensemble.forest

进行打包,运行exe提示No module named 'sklearn.tree.tree',便使用
 pyinstaller -F temp0201.py --hidden-import sklearn.ensemble.forest --hidden-import sklearn.tree.tree 

进行打包,运行exe提示
sklearn\utils\deprecation.py:143: FutureWarning: The sklearn.ensemble.forest module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.ensemble. Anything that cannot be imported from sklearn.ensemble is now part of the private API.
sklearn\utils\deprecation.py:143: FutureWarning: The sklearn.tree.tree module is deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.tree. Anything that cannot be imported from sklearn.tree is now part of the private API.
sklearn\base.py:329: UserWarning: Trying to unpickle estimator DecisionTreeRegressor from version pre-0.18 when using version 0.23.2. This might lead to breaking code or invalid results. Use at your own risk.
Traceback (most recent call last):
File "temp0201.py", line 88, in <module>
model_ran = pickle.loads(s2)
File "sklearn\tree\_tree.pyx", line 655, in sklearn.tree._tree.Tree.__setstate__
KeyError: 'max_depth'

便使用
pyinstaller -F temp0201.py --hidden-import sklearn.ensemble --hidden-import sklearn.tree

进行打包,运行exe再次提示
 No module named 'sklearn.ensemble.forest'

请问大佬们这是发生什么事了,怎么回事
谢谢大佬们



...全文
479 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧