PyInstaller: a module is not included into --onefile, but works fine with --onedir

╄→尐↘猪︶ㄣ 提交于 2019-12-03 05:55:26
Vaibhav Sahu

I had the same error. The solution is to create a hook for sklearn. Generally u need to create a hook file like this

hiddenimports = ['sklearn.utils.sparsetools._graph_validation'] 

and save this in in a file with name hook-modulename.py in the same folder. But this will import only _graph_validation. This might lead to error for another module. Best to import all the submodules in a package by

from hookutils import collect_submodules
hiddenimports = collect_submodules('sklearn') 

and save it to a hook file in the same folder. For me i had to create 2 hook file. one for sklearn and one for scipy.

from hookutils import collect_submodules
hiddenimports = collect_submodules('scipy') 

after saving them i used below command to run

pyinstaller --additional-hooks-dir=. myfile.py

for better understanding follow http://pythonhosted.org/PyInstaller/hooks.html#understanding-pyinstaller-hooks

just import following packages in the script which is going to convert into exe file

 import xgboost
 import sklearn.ensemble
 import sklearn.tree
 import pickle
 import pandas as pd
 import sklearn.neighbors.typedefs
 import sklearn.neighbors.quad_tree
 import sklearn.tree._utils
 import cython
 import sklearn
 import sklearn.utils._cython_blas
 import numpy as np
 import joblib
 from sklearn.preprocessing import StandardScaler

this help me in solving this issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!