Pyinstaller created exe file cannot load Decision Tree model using joblib


I created an exe file of my large python script using the following command –
pyinstaller --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:

ModuleNotFoundError: No module named 'sklearn.ensemble._weight_boosting'

I tried updating the hidden_imports by adding just sklearn.ensemble and sklearn.ensemble._weight_boostin 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([''],

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.

Can anyone suggest steps to make the exe of the script runnable?

Asked By: EyemPri



I had some similar issues and it was solved by collecting the whole sklearn module, not just the one which was missing. I do not understand why, but that solved my problem. Perhaps it will help you too

from PyInstaller.utils.hooks import collect_submodules
hidden_imports = collect_submodules('sklearn')
Answered By: flipSTAR