2
votes

I am using tensorflow with python 2.7. However, after updating python 2.7.10 to 2.7.13, I get an import error with tensorflow

File "", line 1, in 
  File "/Users/usrname/Library/Python/2.7/lib/python/site-
                        packages/tensorflow/__init__.py", line 24, in 
    from tensorflow.python import *
  File "/Users/usrname/Library/Python/2.7/lib/python/site-
                        packages/tensorflow/python/__init__.py", line 63, in 
    from tensorflow.core.framework.graph_pb2 import *
  File "/Users/usrname/Library/Python/2.7/lib/python/site-
                        packages/tensorflow/core/framework/graph_pb2.py", line 6, in 
    from google.protobuf import descriptor as _descriptor
ImportError: No module named google.protobuf

Output from pip install protobuf

Requirement already satisfied: protobuf in /usr/local/lib/python2.7/site-packages 
Requirement already satisfied: setuptools in /Users/usrname/Library/Python/2.7/lib/
    python/site-packages (from protobuf) 
Requirement already satisfied: six>=1.9 in /Library/Python/2.7/site-packages/
    six-1.10.0-py2.7.egg (from protobuf) 
Requirement already satisfied: appdirs>=1.4.0 in /usr/local/lib/python2.7/site-packages
    (from setuptools->protobuf) 
Requirement already satisfied: packaging>=16.8 in /usr/local/lib/python2.7/site-packages 
    (from setuptools->protobuf) 
Requirement already satisfied: pyparsing in /usr/local/lib/python2.7/site-packages 
    (from packaging>=16.8->setuptools->protobuf) 

Output from which python:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

I believe this path changed after the python update, but not sure. A solution could possibly be to downgrade python, but this seems like a bad solution? As I work in a team, I would like to avoid reinstalling Tensorflow due to end up with different versions, but this is perhaps the way to go? Any advice?


Update: I tired to install tensorflow all over, but the same error keeps popping up. Maybe the problem is the environment variables as which pipreturns /usr/local/bin/pip(which is different from which python)?

1
How did you update Python?Mikael Rousson
I downloaded the latest version from their homepage. python.org/downloadssimejo
To avoid issues with python environments, you probably want to use virtualenv. The "nuclear" option is to use docker and do everything in a container.drpng
Ah, okay. I have never done that before, is there a walk-through somewhere?simejo
What happens if you use the newly installed python to import tensorflow: /usr/local/bin/python -c "import tensorflow" ?Mikael Rousson

1 Answers

0
votes

I had a similar problem. Make sure that pip and python has the same path when typing which pipand which python. If they differ, change your ~.bash_profile so that the python path match the pip path, and use source ~\.bash_profile.

If that doesn't work, I would try to reinstall pip and tensorflow.

I installed pip using this command:

wget https://bootstrap.pypa.io/get-pip.py
sudo python2.7 get-pip.py