tensorflow: import tf fails in "imp.find_module('_pywrap_tensorflow_internal',"

I get error below trying to import TensorFlow built at commit 7e9f2dc (head as of Sat 4).

I haven’t made any changes to my build procedure in last month, and installing similarly built wheel from Mar 1 works.

Looking at relevant differences between Mar 1 and Mar 4 I see that @jhseu 's 718812c refactored Python module loading in https://github.com/tensorflow/tensorflow/blob/b10f50ff15944badb7262a207f6628dfa52d6a9d/tensorflow/python/pywrap_tensorflow.py

Stack trace

Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 51, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/yaroslav/.conda/envs/tf-mar4/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ImportError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 18 (10 by maintainers)

Most upvoted comments

make sure you aren’t getting this error as a result of running python from the actual git directory where you downloaded tensorflow.

if you’re following the step-by-step install from the documentation page, and get to the final step where you verify the install, you start python from the terminal and run ‘import tensorflow’, and you would get this error. go to any other directory and you’re fine.

This 1.0.0 build was such a pain! After way more time that I wanted to on this, I got something that works on MacOS.

  1. First I had to deal with a Mac-specific issue where a protection scheme, SIP, prevents you from defining DYLD_ anything in env, so it could not find libcudart.8.0.dylib. This dude blogged a workaround - https://srikanthpagadala.github.io/notes/2016/11/07/enable-gpu-support-for-tensorflow-on-macos

  2. Then I ran into an issue where it could not find another library, libcublas. Since I used Homebrew (as per all guidance everywhere) to get bazel, it got 0.4.4 which doesn’t work with this source. Someone posted on this issue how to roll back to 0.4.3 - https://github.com/tensorflow/tensorflow/issues/7227

  3. Finally, the problem you are all having here. After finally getting the build and installing the wheel in my conda env, I ran into an error trying to find pywrap_tensorflow_internal.so when I ran the interpreter and tried to import tensorflow. Turns out the wheel had one error while being assembled. I looked at the conda env site packages to see if the .so is actually there. It was, but it was named _pywrap_tensorflow_internal.so (notice the initial underscore). I removed the underscore by hand and it finally worked. 😕 This last bit might help you guys on Linux maybe?