6
votes

Trying to distribute a program that relies on tensorflow...

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.

I use python 3.6.5 and tensorflow 1.7.0. (Can change version if it helps...)

Error message:

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'

During handling of the above exception, another exception occurred:

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'

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

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

3
Sometimes errors like that come up when the current directory has a tensorflow subdirectory with an __init__.py in it, which Python will prefer to any other installations. (Or something similar; a tensorflow.py might work too.)Allen Lavoie
I have same issue. Did you end up solving it Aleksk89?Dominic Bou-Samra
Unfortunately notAleksk89

3 Answers

2
votes

Make sure you are also packaging MSVCP140.DLL, as missing this from the %PATH% can throw this error.

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.

1
votes

Maybe this can help. I manually rename the file _pywrap_tensorflow_internal.pyd to tensorflow.python._pywrap_tensorflow_internal.pyd in the dist folder. Everything works.

1
votes

I fixed this problem by making dirs as ".../dist/[MmyPyName]/tensorflow/python/_pywrap_tensorflow_internal.pyd"

  • tensorflow-gpu = 1.10.0
  • python = 3.6.2
  • cuda = 9.0
  • cudnn = 7.3.0