tensorflow import error. With /Library/Python/2.7/site-packages not included
<p>Trying to install tensorflow. Tried anaconda, it worked but affected my other program. Then decided to use pip install.</p>

<p>But after I installed it, I just can't import it within ipython.</p>

<p>Here are the messages: I tried uninstall and reinstall.</p>

<pre><code>pip install tensorflow
Requirement already satisfied (use --upgrade to upgrade): tensorflow in /Library/Python/2.7/site-packages 
Cleaning up...
</code></pre>

<p>First I try to import in ipython:</p>

<pre><code>In [1]: import tensorflow
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
&lt;ipython-input-1-a649b509054f&gt; in &lt;module&gt;()
----&gt; 1 import tensorflow

ImportError: No module named tensorflow
</code></pre>

<p>And then I copied the folder of tensorflow from /Library/Python/2.7/site-packages to /usr/local/lib/python2.7/site-packages/. I try to import:</p>

<pre><code>In [1]: import tensorflow
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
&lt;ipython-input-1-a649b509054f&gt; in &lt;module&gt;()
----&gt; 1 import tensorflow

/Library/Python/2.7/site-packages/tensorflow/__init__.py in &lt;module&gt;()
     21 from __future__ import print_function
     22 
---&gt; 23 from tensorflow.python import *
     24 
     25 

/Library/Python/2.7/site-packages/tensorflow/python/__init__.py in &lt;module&gt;()
     57 please exit the tensorflow source tree, and relaunch your python interpreter
     58 from there.""" % traceback.format_exc()
---&gt; 59   raise ImportError(msg)
     60 
     61 from tensorflow.core.framework.node_def_pb2 import *

ImportError: Traceback (most recent call last):
  File "tensorflow/python/__init__.py", line 53, in &lt;module&gt;
    from tensorflow.core.framework.graph_pb2 import *
  File "tensorflow/core/framework/graph_pb2.py", line 6, in &lt;module&gt;
    from google.protobuf import descriptor as _descriptor
ImportError: No module named google.protobuf


Error importing tensorflow.  Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.
</code></pre>

<p>However, I have protobuf installed under /Library/Python/2.7/site-packages as well.</p>

<p>I find out this version of ipython is using macports python package directory:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/</p>

<p>I am not sure how to let ipython search for the pip installed directory.</p>

<p>I reinstalled the tensorflow again as it is described on the website:</p>

<pre><code>sudo pip install --upgrade $TF_BINARY_URL
Password:
Downloading/unpacking https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0rc0-py2-none-any.whl
  Downloading tensorflow-0.11.0rc0-py2-none-any.whl (35.5MB): 35.5MB downloaded
Downloading/unpacking protobuf==3.0.0 (from tensorflow==0.11.0rc0)
  Downloading protobuf-3.0.0-py2.py3-none-any.whl (342kB): 342kB downloaded
Requirement already up-to-date: wheel in /Library/Python/2.7/site-packages (from tensorflow==0.11.0rc0)
Requirement already up-to-date: mock&gt;=2.0.0 in /Library/Python/2.7/site-packages (from tensorflow==0.11.0rc0)
Requirement already up-to-date: numpy&gt;=1.11.0 in /Library/Python/2.7/site-packages (from tensorflow==0.11.0rc0)
Requirement already up-to-date: six&gt;=1.10.0 in /Library/Python/2.7/site-packages (from tensorflow==0.11.0rc0)
Downloading/unpacking setuptools from https://pypi.python.org/packages/be/20/3f4d2fb59ddeed35532bd4e11e900abcf8019d29f4558d38169639303536/setuptools-28.2.0-py2.py3-none-any.whl#md5=02e79b1127c5a131a2dace6d30cf7f25 (from protobuf==3.0.0-&gt;tensorflow==0.11.0rc0)
  Downloading setuptools-28.2.0-py2.py3-none-any.whl (467kB): 467kB downloaded
Installing collected packages: tensorflow, protobuf, setuptools
  Found existing installation: protobuf 3.1.0.post1
    Uninstalling protobuf:
      Successfully uninstalled protobuf
  Found existing installation: setuptools 18.5
    Uninstalling setuptools:
      Successfully uninstalled setuptools
Successfully installed tensorflow protobuf setuptools
Cleaning up...
</code></pre>

<p>And still no luck:</p>

<pre><code>In [1]: import tensorflow
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
&lt;ipython-input-1-a649b509054f&gt; in &lt;module&gt;()
----&gt; 1 import tensorflow
</code></pre>

<p>OK, I got the problem fixed.</p>

<p>I am not sure what exactly is causing it. Because I installed all this on my RMBP, nothing wrong. But desktop just won't take it.</p>

<p>Solution is:</p>

<p>Uninstall all previously installed or half installed tensorflow, and my other packages (just two main packages). And use anaconda to install tensorflow, activate it. And use anaconda to install my other packages.</p>

<p>Then problem solved.</p>

python ipython tensorflow