Hope this helps anyone having
'ModuleNotFoundError: No module named 'sklearn.*'' 'ModuleNotFoundError: No module named 'h5py.*'' 'ModuleNotFoundError: No module named 'sklearn.*''
During or after the pyinstaller build
Example if you get an error for h5py
After running pyinstaller myscript.py myscript.spec generated
myscript.spec inside myscript.spec
# -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis(['myscript.py'], binaries=None, datas=[], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None)
add
from PyInstaller.utils.hooks import collect_submodules hidden_imports = collect_submodules('h5py')
and
hiddenimports=hidden_imports,
Like this
# -*- mode: python ; coding: utf-8 -*- block_cipher = None from PyInstaller.utils.hooks import collect_submodules hidden_imports = collect_submodules('h5py') a = Analysis(['myscript.py'], binaries=None, datas=[], hiddenimports=hidden_imports, hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None)
Then save myscript.spec and run the pyinstaller myscript.spec
Credit 9dogs Pyinstaller created EXE file cannot load model Keras NN