我正在尝试使用使用 tensorflow 的 pyinstaller 捆绑一个 python 应用程序。
我现在在虚拟环境中使用 Pyinstaller-4.0.dev0+2f4426f52、Tensorflow 2.0、Keras 2.3 和 Python 3.7.3。
我尝试了各种旧版本,但每个旧版本都有我无法解决的不同问题。我花了 3 天时间来尝试解决这个问题。
我正在运行的脚本的一个简化示例是:
from tensorflow import keras
model = keras.Sequential()
Run Code Online (Sandbox Code Playgroud)
我使用以下命令运行 pyinstaller:
pyinstaller --noconfirm --log-level=DEBUG ^
--onedir ^
--clean ^
--name MyModel ^
--hidden-import=tensorflow_core ^
--noupx ^
main.py
Run Code Online (Sandbox Code Playgroud)
使用隐藏导入似乎是多余的,因为输出状态:
调试:已找到隐藏的导入“tensorflow_core”
日志中没有构建错误或警告。
我查看了 pyz-00.pyz 文件,可以确认文件中包含 TensorFlow 模块。我确认存档包含:
'tensorflow_core.python': (1, 9871434, 2355),
但是,当我尝试运行 exe 时,出现以下错误:
文件“site-packages\tensorflow_core\python_init_.py”,第 49 行,在 ImportError 中:无法从 'tensorflow_core.python' (\dist\MyModel\tensorflow_core\python_init_.pyc) 导入名称 'pywrap_tensorflow'
pyinstaller 似乎无法处理 tensorflow,我想知道这里有经验的人是否知道如何为其编写钩子或知道其他一些解决方法?