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

Closed
isec1971 opened this Issue Jan 26, 2016 · 16 comments

Comments

Projects
None yet
@isec1971

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

This comment has been minimized.

Show comment
Hide comment
@vrv

vrv Jan 26, 2016

Contributor

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.

Contributor

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 Jan 26, 2016

@isec1971

This comment has been minimized.

Show comment
Hide comment
@isec1971

isec1971 Jan 27, 2016

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

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

This comment has been minimized.

Show comment
Hide comment
@JACKHAHA363

JACKHAHA363 Feb 4, 2016

Exactly same question here.

Exactly same question here.

@Grzego

This comment has been minimized.

Show comment
Hide comment
@Grzego

Grzego 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

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

This comment has been minimized.

Show comment
Hide comment
@hazelement

hazelement Feb 25, 2016

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

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

This comment has been minimized.

Show comment
Hide comment
@hazelement

hazelement Feb 25, 2016

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'

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

This comment has been minimized.

Show comment
Hide comment
@markusdr

markusdr 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.

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

This comment has been minimized.

Show comment
Hide comment
@mznyc

mznyc Mar 13, 2016

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

mznyc commented Mar 13, 2016

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

@cerisara

This comment has been minimized.

Show comment
Hide comment
@cerisara

cerisara 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.

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

This comment has been minimized.

Show comment
Hide comment
@bingfeng1018

bingfeng1018 May 17, 2016

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

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

@stephanobryan

This comment has been minimized.

Show comment
Hide comment
@stephanobryan

stephanobryan Aug 23, 2016

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 :)

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

This comment has been minimized.

Show comment
Hide comment
@anna-liao

anna-liao Oct 14, 2016

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

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

@deatherving

This comment has been minimized.

Show comment
Hide comment
@deatherving

deatherving Oct 24, 2016

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.

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

This comment has been minimized.

Show comment
Hide comment
@robksawyer

robksawyer Dec 22, 2016

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'
>>> 

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

This comment has been minimized.

Show comment
Hide comment
@hoangcuong2011

hoangcuong2011 Aug 24, 2017

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!

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!

@aboucaud aboucaud referenced this issue in paris-saclay-cds/ramp-workflow Sep 16, 2017

Merged

Making ramp_workflow pip installable #50

@bmatichuk

This comment has been minimized.

Show comment
Hide comment
@bmatichuk

bmatichuk Oct 25, 2017

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment