tensorflow: ImportError: No module named google.protobuf

Problem description This issue happens randomly. For same machine, same CPU,works randomly. I run it for 10 times, 6 times succeed, 4 times fail. Same code is running for every time. The code is

import tensorflow as tf
# with tf.device('/cpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
	print sess.run(c)

System information Information of cluster: Basically our cluster is made of IBM Power System S822LC for commercial computing

OS: Red Hat Enterprise Linux Server release 7.2 (Maipo)
TF version: 0.10.0rc0
protobuf: 3.0.0b2
Python: 2.7.5

Error

>>> import os
>>> cwd = os.getcwd()
>>> cwd
'/gpfs/gpfs0/groups/duraisamy/shawnpan/test/script'
>>> import tensorflow
import tensorflow
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so.5.1.5 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so.8.0 locally
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/gpfs/gpfs0/software/rhel72/packages/tensorflow_gpu/tensorflow/__init__.py", line 23, in <module>
    from tensorflow.python import *
  File "/gpfs/gpfs0/software/rhel72/packages/tensorflow_gpu/tensorflow/python/__init__.py", line 58, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/gpfs/gpfs0/software/rhel72/packages/tensorflow_gpu/tensorflow/python/__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/gpfs/gpfs0/software/rhel72/packages/tensorflow_gpu/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
    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.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 28 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I install tensorflow with virtualenv. pip uninstall protobuf pip uninstall google pip install google pip install protobuf That is ok,but I don’t know why

the __init__.py file is missing in site-packages/google directory. creating an empty __init__.py file there should work. thanks. @fangbq

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

pip install google doesn’t work for me I just pip install google-cloud and it works

Finally installed with conda conda install protobuf

Finally installed with conda conda install protobuf

It was the solution in my case. Thank you. pip was the problem. I am using conda environment. Use conda install!

Again: Double-check that there is no __init__.py in your site-packages/google folder or delete it if there is. Easier than the uninstall dance which may or may not work. BTW: You probably do NOT want to install the “google” package: That is the Python bindings to google search engine. Why would you want that in this context? Oh and it trashes your namespace s mentioned in https://github.com/tensorflow/tensorflow/issues/6341#issuecomment-553769366

I’m following this guide and every step worked fine except of the last one, When i try to run the benchmark i get this error.

Traceback (most recent call last):
  File "scripts/tf_cnn_benchmarks/tf_cnn_benchmarks.py", line 25, in <module>
    import tensorflow as tf
  File "/home/zwazel/.local/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/zwazel/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/home/zwazel/.local/lib/python3.6/site-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
    from google.protobuf import descriptor as _descriptor
ModuleNotFoundError: No module named 'google.protobuf'

I tried all of the above things and nothing worked. Can someone help me or should i open a new issue for this? I’m running it on a Jetson Nano with Ubuntu 18.04 LTS