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:
ModuleNotFoundError: No module named 'sklearn.ensemble._weight_boosting'
I tried updating the hidden_imports by adding just
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(['gui_final.py'], binaries=None, datas=, hiddenimports=hidden_imports, . .
By running the command:
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?
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')