问题描述
试图分发一个依赖 tensorflow 的程序...
Trying to distribute a program that relies on tensorflow...
使用 tensorflow,它可以很好地作为脚本和 pyinstaller 工作.使用 tensorflow-gpu 它可以作为脚本工作,但不能与 pyinstaller 一起使用.cuda 和 cudnn dll 已被 pyinstaller 复制到 bundle 文件夹中.
Using tensorflow it works nicely both as script and with pyinstaller.Using tensorflow-gpu it works as script but not with pyinstaller.The cuda and cudnn dlls have been copied into the bundle folder by pyinstaller.
我使用 python 3.6.5 和 tensorflow 1.7.0.(如果有帮助可以更改版本...)
I use python 3.6.5 and tensorflow 1.7.0. (Can change version if it helps...)
错误信息:
回溯(最近一次调用最后一次):文件site-packages\tensorflow\python\pywrap_tensorflow.py",第 58 行,在文件c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",第 631 行,在 exec_module 中exec(字节码,模块.dict)文件site-packages\tensorflow\python\pywrap_tensorflow_internal.py",第 18 行,在文件site-packages\tensorflow\python\pywrap_tensorflow_internal.py",第 17 行,在 swig_import_helper文件importlib__init__.py",第 126 行,在 import_module 中ModuleNotFoundError: 没有名为tensorflow.python._pywrap_tensorflow_internal"的模块
在处理上述异常的过程中,又发生了一个异常:
During handling of the above exception, another exception occurred:
回溯(最近一次调用最后一次):文件interface.py",第 14 行,在文件c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",第 631 行,在 exec_module 中exec(字节码,模块.dict)文件site-packages\tensorflow__init__.py",第 24 行,在文件c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",第 631 行,在 exec_module 中exec(字节码,模块.dict)文件site-packages\tensorflow\python__init__.py",第 49 行,在文件c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",第 631 行,在 exec_module 中exec(字节码,模块.dict)文件site-packages\tensorflow\python\pywrap_tensorflow.py",第 74 行,在导入错误:回溯(最近一次调用最后一次):文件site-packages\tensorflow\python\pywrap_tensorflow.py",第 58 行,在文件c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",第 631 行,在 exec_module 中exec(字节码,模块.dict)文件site-packages\tensorflow\python\pywrap_tensorflow_internal.py",第 18 行,在文件site-packages\tensorflow\python\pywrap_tensorflow_internal.py",第 17 行,在 swig_import_helper文件importlib__init__.py",第 126 行,在 import_module 中ModuleNotFoundError:没有名为tensorflow.python._pywrap_tensorflow_internal"的模块
Traceback (most recent call last): File "interface.py", line 14, in File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module exec(bytecode, module.dict) File "site-packages\tensorflow__init__.py", line 24, in File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module exec(bytecode, module.dict) File "site-packages\tensorflow\python__init__.py", line 49, in File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module exec(bytecode, module.dict) File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in ImportError: Traceback (most recent call last): File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module exec(bytecode, module.dict) File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper File "importlib__init__.py", line 126, in import_module ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_internal'
无法加载本机 TensorFlow 运行时.
Failed to load the native TensorFlow runtime.
请参阅https://www.tensorflow.org/install/install_sources#common_installation_problems
出于一些常见原因和解决方案.包括整个堆栈跟踪寻求帮助时出现在此错误消息上方.[10816] 无法执行脚本界面
for some common reasons and solutions. Include the entire stack trace above this error message when asking for help. [10816] Failed to execute script interface
推荐答案
确保您还打包了 MSVCP140.DLL
,因为在 %PATH% 中缺少它会引发此错误.
Make sure you are also packaging MSVCP140.DLL
, as missing this from the %PATH% can throw this error.
在分发 tensorflow 应用程序时,我倾向于使用 cx_Freeze 而不是 pyinstaller.一旦你克服了 cx_Freeze 与 scipy 的错误,它总体上就更简单了.
I tend to use cx_Freeze instead of pyinstaller when distributing tensorflow applications. Once you overcome the error cx_Freeze has with scipy, it's simpler overall.
这篇关于带有 pyinstaller 的 Tensorflow-gpu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!