[SOLVED] Pyinstaller and sklearn.ensemble: ‘ModuleNotFoundError: No module named ‘sklearn.neighbors.quad_tree’ [2760]’


This Content is from Stack Overflow. Question asked by EyemPri

I created an exe file of my large python script using the following command –
pyinstaller gui_final.py --onefile --hidden-import=sklearn --hidden-import=ipaddress --hidden-import=PIL --hidden-import=pickle --hidden-import=shutil --hidden-import=joblib

The exe file works fine until I load my decision tree model file (dtree.joblib) using JOBLIB.

clf = joblib.load("dtree.joblib")

The following error pops up – Here is the complete error in the terminal.
tldr; this is the error – ModuleNotFoundError: No module named ‘sklearn.ensemble._weight_boosting’

I tried updating the hidden_imports by adding just “sklearn.ensemble” and “sklearn.ensemble._weight_boosting” later to the spec file of the exe by following steps in this answer. steps also given below

from PyInstaller.utils.hooks import collect_submodules

hidden_imports = collect_submodules('sklearn.ensemble') #('sklearn.ensemble._weight_boosting')

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

By running the command –

pyinstaller gui_final.spec

But still got the same ModuleNotFoundError as earlier after running the exe.

I have tried looking at some issues regarding joblib with pyinstaller, but have not found any suitable issues or solutions.

If anyone has experience of using joblib with pyinstaller pls suggest steps to make the exe of the script runnable

Thanks in advance


I ran into the same problem with sklearn and pyinstaller.

Here is how I resolved it:

1.)Use command:

> pyi-makespec -F visual_vitals.py

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

3.)Find line with

> hidden imports=[]

in the spec file.

Replace it with

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

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

> import sys 
> sys.setrecursionlimit(5000)

5.)Run :

> pyinstaller visual_vitals.spec

This Question was asked in StackOverflow by ignoring_gravity and Answered by Sumit Paroothi It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?