Pyinstaller created exe file cannot load Decision Tree model using joblib


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 --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([''],

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


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, 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?