且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

pyinstaller创建的exe文件无法加载keras nn模型

更新时间:2023-12-01 23:20:28

如果您收到有关h5py子模块的错误,请尝试使用 collect_submodules函数,将它们全部添加到hidden_imports.

If you get errors about h5py submodules, try to use collect_submodules function to add them all to hidden_imports.

您可能已经注意到pyinstaller生成的名为myscript.spec的文件.该文件中包含有关如何构建脚本的说明(它也只是python代码!).

You probably noticed a file called myscript.spec generated by a pyinstaller. Inside this file is an instruction on how to build you script (and it's just a python code too!).

因此,请尝试像这样编辑myscript.spec:

So try to edit this myscript.spec like this:

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)

# ... rest of a file untouched

然后针对该文件pyinstaller myscript.spec运行pyinstaller.