本文介绍了Pyinstaller和sklearn.ensemble:'ModuleNotFoundError:没有名为'sklearn.neighbors.quad_tree'的模块[2760]'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在PyQt5中编写了一个GUI,其中包括以下行from sklearn.ensemble import RandomForestClassifier.

I have written a GUI in PyQt5 which includes the linefrom sklearn.ensemble import RandomForestClassifier.

按照答案中的建议,在\Anaconda3\Lib\site-packages\PyInstaller\hooks中,我添加了一个名为hook-pandas.py的文件,其中包含以下:

Following the suggestion in this answer, in \Anaconda3\Lib\site-packages\PyInstaller\hooks, I have added a file called hook-pandas.py which contains the following:

hiddenimports = ['pandas._libs.tslibs.timedeltas', 'sklearn.neighbors.typedefs']

hiddenimports = ['pandas._libs.tslibs.timedeltas', 'sklearn.neighbors.typedefs']

之后,我尝试运行pyinstaller -F visual_vitals.py --hidden-import sklearn.neighbors.typedefs在Anaconda提示中.

After that, I tried runningpyinstaller -F visual_vitals.py --hidden-import sklearn.neighbors.typedefsin the Anaconda Prompt.

但是,我得到了错误RecursionError: maximum recursion depth exceeded.

However, I get the errorRecursionError: maximum recursion depth exceeded.

另一方面,如果我只是跑步pyinstaller visual_vitals.py'

If, on the other hand, I just run`pyinstaller visual_vitals.py'

然后正确构建.exe,当我尝试运行它时,我收到消息modulenotfounderror: no module named 'sklearn.neighbors.quad_tree'.

then the .exe builds correctly, when I try running it, I get the messagemodulenotfounderror: no module named 'sklearn.neighbors.quad_tree'.

我该怎么办?

请注意,如果我使用支持向量分类器而不是随机森林,则该问题消失了,因此问题是特定于此分类器而不是整个sklearn.

Note that the problem disappears if, instead of a random forest, I use a support vector classifier, so the problem is specific to this classifier rather than to the whole of sklearn.

推荐答案

我在sklearn和pyinstaller中遇到了同样的问题.

I ran into the same problem with sklearn and pyinstaller.

这是我的解决方法:

1.)使用命令:

> pyi-makespec -F visual_vitals.py

2.)这将创建一个名为vitals.spec的文件

2.)This will create a file by name vitals.spec

3.)使用

> hidden imports=[]

在规格文件中.

> hiddenimports = ['pandas._libs.tslibs.timedeltas',
>                  'sklearn.neighbors.typedefs']

4.)在规范文件的开头添加这两行以增加递归限制

4.)Add these two lines to increase recursion limit at beginning of the spec file

> import sys
>
> sys.setrecursionlimit(5000)

5.)运行:

> pyinstaller visual_vitals.spec

这篇关于Pyinstaller和sklearn.ensemble:'ModuleNotFoundError:没有名为'sklearn.neighbors.quad_tree'的模块[2760]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:20