I have a python file main.py
which references to gauss.py
which uses import sklearn.mixture
and from this package I am using the function GaussianMixture()
.
I want to pack main.py
into an .exe file with PyInstaller.
It seems to be a common problem, that PyInstaller will not find sklearn or included modules on its own, i get this error after simply calling pyinstaller main.py
:
>main.exe
Traceback (most recent call last):
File "main.py", line 24, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "gauss.py", line 12, in <module>
ModuleNotFoundError: No module named 'sklearn'
[5304] Failed to execute script 'main' due to unhandled exception!
As the first answer in this question suggests, you have to add specific modules as hidden imports.
The first answer in this question suggests to create hook files (hook-modulename.py
and hook-modulename.tree.py
can be found in various answers regarding this problem).
Checking \Programs\Python\Python38\Lib\site-packages\PyInstaller\hook
I cannot find any hook files referencing sklearn.
How do I know, which hook files to create, which (utility) modules are missing from sklearn and what to write into the hook files (I've found mulitple solutions)? I found plenty solutions to problems which are similar but not identical to mine, but they vary in such a way, that I don't understand what to do in my case. Strictly following the other solutions obviously does not work.
Can somebody please explain what the problem with the architecture of sklearn is, and how to create the hook files exactly?