WestCoastProjects
WestCoastProjects

Reputation: 63022

Tensorflow ImportError on OS X

TL;DR getting ImportError: cannot import name pywrap_tensorflow when trying to use TensorFlow on El Capitan.

Details: I followed the TensorFlow installation instructions for Mac OS X from here.

Mac OS X, CPU only, Python 2.7:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0rc0-py2-none-any.whl

$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0rc0-py2-none-any.whl

$ sudo pip install --upgrade $TF_BINARY_URL

These steps were successful.

So let's try it:

22:54:00/tensorflow $ipython
Python 2.7.11 (default, Jan 22 2016, 08:29:18)
Type "copyright", "credits" or "license" for more information.

IPython 4.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
[TerminalIPythonApp] WARNING | File not found: '/shared/.pythonstartup'

In [1]: import tensorflow as tf
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-41389fad42b5> in <module>()
----> 1 import tensorflow as tf

/git/tensorflow/tensorflow/__init__.py in <module>()
     21 from __future__ import print_function
     22
---> 23 from tensorflow.python import *

/git/tensorflow/tensorflow/python/__init__.py in <module>()
     46 _default_dlopen_flags = sys.getdlopenflags()
     47 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 48 from tensorflow.python import pywrap_tensorflow
     49 sys.setdlopenflags(_default_dlopen_flags)
     50

ImportError: cannot import name pywrap_tensorflow

Upvotes: 2

Views: 2825

Answers (1)

mrry
mrry

Reputation: 126154

TL;DR: Don't run ipython (or python) from the root of the TensorFlow git repository when you want to import tensorflow.

I answered a similar question here. The easiest solution is to cd out of the current directory (e.g. cd ~) before running ipython. This will prevent Python from being confused by the tensorflow source subdirectory in the current path. The ./tensorflow directory in the git repository doesn't contain all of the generated code (such as pywrap_tensorflow) that is needed to run TensorFlow, but does contain a file called __init__.py, and this confuses the Python interpreter.

Upvotes: 3

Related Questions