Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ImportError: No module named protobuf" on El Capitan with VirtualEnv #890

Closed
isec1971 opened this issue Jan 26, 2016 · 17 comments
Closed

Comments

@isec1971
Copy link

Hello,
When I try importing tensorflow in Python I get "ImportError: No module named protobuf".

I followed instructions from here https://www.tensorflow.org/versions/0.6.0/get_started/os_setup.html#virtualenv_install and also updated protobuf:

brew reinstall --devel protobuf

The version I have is 3.0.0a3

I looked at the issues here and all remedies don't seem to work.

Any clue?

Thx

@vrv
Copy link

vrv commented Jan 26, 2016

There is not nearly enough information for anybody to help. If you add more information about your setup, what you've tried, etc., we might be able to offer help, and I'll reopen the issue.

@vrv vrv closed this as completed Jan 26, 2016
@isec1971
Copy link
Author

I apologize, I am new to this and wasn't sure what level of details is needed.

Host: El Capitan 10.11.3

Repro steps:
$ sudo easy_install pip
$ sudo pip install --upgrade virtualenv
$ virtualenv --system-site-packages ~/tensorflow
$ source ~/tensorflow/bin/activate
(tensorflow)$ pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl

Then I tried to test

$ python

import tensorflow as tf

I got this:

Traceback (most recent call last):
File "", line 1, in
File "/Users/xxx/tensorflow/lib/python2.7/site-packages/tensorflow/init.py", line 4, in
from tensorflow.python import *
File "/Users/xxx/tensorflow/lib/python2.7/site-packages/tensorflow/python/init.py", line 13, in
from tensorflow.core.framework.graph_pb2 import *
File "/Users/xxx/tensorflow/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 6, in
from google.protobuf import descriptor as _descriptor
ImportError: No module named protobuf

then I quit python and executed this:

$ brew reinstall --devel protobuf

this command :
$ pip freeze

shows:
protobuf==3.0.0a3

I then try again with python, same commands as above, and get the exact same error as above.

Please let me know if you need other kind of details. I will send them.

Thanks,
Pierre

@JACKHAHA363
Copy link

Exactly same question here.

@Grzego
Copy link

Grzego commented Feb 8, 2016

I had the same error and those steps worked for me (although I did not use any virtual environments):

pip uninstall protobuf
pip install protobuf
pip install --upgrade protobuf==3.0.0a3

@hazelement
Copy link

tried Grzego's approach. Got a new error though...

import tensorflow as tf File "/usr/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module> from tensorflow.python import * File "/usr/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 69, in <module> from tensorflow.python.training import training as train File "/usr/local/lib/python2.7/site-packages/tensorflow/python/training/training.py", line 149, in <module> from tensorflow.python.training.saver import generate_checkpoint_state_proto File "/usr/local/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 29, in <module> from google.protobuf.any_pb2 import Any ImportError: No module named any_pb2

@hazelement
Copy link

ended up creating a new virtualenv and now it's working. noticed a new protobuf was installed
'Successfully installed protobuf-3.0.0b2 tensorflow-0.7.1'

@markusdr
Copy link

markusdr commented Mar 6, 2016

I had the same problem on my Mac. Like @FiniteElementries, I ran into the error No module named any_pb2. Solution:

pip uninstall protobuf
pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl

After that, tensorflow works fine for me.

@mznyc
Copy link

mznyc commented Mar 13, 2016

Try this. Will likely solve the problem
sudo pip install --upgrade protobuf==3.0.0b2

@cerisara
Copy link

cerisara commented Apr 1, 2016

I ran into the same problems, which are likely due to conflict with old versions.
Got it run with:
sudo pip uninstall protobuf
sudo pip uninstall tensorflow
and then install again tensorflow as said in the TF install page.

@bingfeng1018
Copy link

as markusdr said, it worked! thanks!
pip uninstall protobuf
pip install /tmp/tensorflow_pkg/tensorflow*.whl

@stephanobryan
Copy link

On El Capitan 10.11.6 and within Virtualenv environment, I've got:
ImportError: No module named protobuf
So I did:
(tensorflow) $ sudo -H pip install protobuf
(tensorflow) $ sudo easy_install -U six
Then,
(tensorflow) $ python

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
Hello, TensorFlow!
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))
42
So, it worked :)

@anna-liao
Copy link

May want to look at this issue: #1415
There are workarounds mentioned there.

@deatherving
Copy link

I got the same problem.

It could be fixed by

sudo pip install --upgrade protobuf

and then protobuf-3.0.0 will be replaced by protobuf-3.1.0. Nailed it.

@robksawyer
Copy link

I keep getting the following even after using the protobuf upgrade mentioned above. Any ideas?

I'm on El Capitan 10.12.1 using Python 2.7.12

$ python
Python 2.7.12 (default, Oct 11 2016, 05:20:59) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 63, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 16, in <module>
    from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
  File "/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/node_def_pb2.py", line 16, in <module>
    from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
  File "/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
  File "/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
    from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
  File "/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/resource_handle_pb2.py", line 22, in <module>
    serialized_pb=_b('\n/tensorflow/core/framework/resource_handle.proto\x12\ntensorflow\"m\n\x0eResourceHandle\x12\x0e\n\x06\x64\x65vice\x18\x01 \x01(\t\x12\x11\n\tcontainer\x18\x02 \x01(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\thash_code\x18\x04 \x01(\x04\x12\x17\n\x0fmaybe_type_name\x18\x05 \x01(\tB4\n\x18org.tensorflow.frameworkB\x13ResourceHandleProtoP\x01\xf8\x01\x01\x62\x06proto3')
TypeError: __init__() got an unexpected keyword argument 'syntax'
>>> 

@hoangcuong2011
Copy link

This is a very annoying problem. I fixed the problem by following @markusdr.
Note that the latest protobuf to date is 3.4.0, so I changed the command as this:

pip install --upgrade protobuf==3.4.0

Hope this helps!

@bmatichuk
Copy link

On Mac OS - Installing tensorflow 1.3 - it will automatically remove other protobuf installs and install protobuf 3.4. However, this does not work and neither does installing or downgrading to any other protobuf version.

However I found a solution.
Not sure why this works - but on Mac OS this solved it.

pip install google

@crafet
Copy link

crafet commented Oct 26, 2018

meet same problems.
pip uninstall tensorflow
pip install tensorflow
it works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests