Protobuf: Getting ModuleNotFoundError: No module named 'google.protobuf'

Created on 14 May 2019  Â·  9Comments  Â·  Source: protocolbuffers/protobuf

Language: Python
protobuf: 3.7.1

What operating system (Linux, Windows, ...) and version?
Windows 10

What runtime / compiler are you using (e.g., python version or gcc version)
Python 3.6.5

What did you do?

I am coding a game and on running it I am getting-
Traceback (most recent call last): File "<frozen importlib._bootstrap>", line 968, in _find_and_load SystemError: <class '_frozen_importlib._ModuleLockManager'> returned a result with an error set ImportError: numpy.core._multiarray_umath failed to import ImportError: numpy.core.umath failed to import Traceback (most recent call last): File "qlearn.py", line 17, in <module> from keras.initializers import normal, identity File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\__init__.py", line 3, in <module> from . import utils File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\__init__.py", line 6, in <module> from . import conv_utils File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module> from .. import backend as K File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\__init__.py", line 89, in <module> from .tensorflow_backend import * File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module> import tensorflow as tf File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module> from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module> from tensorflow.core.framework.graph_pb2 import * File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\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'

installation python windows

All 9 comments

Have you installed grpcio? And grpcio-tools?

@wangjunbao2018 Yeah, I have installed both of them. I am not able to debug even after spending hours on stackoverflow.

Oooh, I think I have told you a incorrect answer, grpcio and grpcio-tools is for commucation. I think you should install protobuf.

Here are some links maybe can help you:

@wangjunbao2018 @anandolee Help needed. On another code I am again getting similar error-
Using TensorFlow backend. Traceback (most recent call last): File "qlearn.py", line 17, in <module> from keras.initializers import normal, identity File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\__init__.py", line 3, in <module> from . import utils File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\__init__.py", line 6, in <module> from . import conv_utils File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module> from .. import backend as K File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\__init__.py", line 89, in <module> from .tensorflow_backend import * File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module> import tensorflow as tf File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module> from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module> from tensorflow.core.framework.graph_pb2 import * File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\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'

This is frustrating me now. i am getting the same on another -
Traceback (most recent call last): File "TD3_BipedalWalker-v2.py", line 14, in <module> from tensorboardX import SummaryWriter File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorboardX\__init__.py", line 5, in <module> from .torchvis import TorchVis File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorboardX\torchvis.py", line 11, in <module> from .writer import SummaryWriter File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorboardX\writer.py", line 14, in <module> from .event_file_writer import EventFileWriter File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorboardX\event_file_writer.py", line 28, in <module> from .proto import event_pb2 File "C:\Users\Win 10\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorboardX\proto\event_pb2.py", line 6, in <module> from google.protobuf import descriptor as _descriptor ModuleNotFoundError: No module named 'google.protobuf'

Can you check if for all google folders in your python package paths (sys.path) there is NO __init__.py?

I encountered that error when using a system/Easybuild installed tensorflow which contained a protobuf egg folder with an __init__.py together with some other, user installed google packages where the file messed up python package search. See http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-init-py-trap for details

So: Delete all __init__.py files in the google folder (only!) and see if this helps. And maybe find out which package placed that init file there.

Reinstall your protobuf and google

This Problem will be caused in TensorFlow's official docker when we install tensorflow_datasets. (I checked at 2.0.0-gpu-py3, 2.1.0-gpu-py3)

We need to REINSTALL protobuf and INSTALL google.

Here is the smallest examples.

dockerfile

FROM tensorflow/tensorflow:2.1.0-gpu-py3
RUN pip install -U pip
RUN pip install tensorflow_datasets

docker-compose.yml

version: '2.3'
services:
  tensorflow:
    build: .
    volumes:
      - ./:/workspace/Github
      - /tmp:/tmp
    runtime: nvidia

run_script.sh

#!/bin/sh

docker-compose run --rm tensorflow /bin/bash
# -u $(id -u):$(id -g)
 $ sh run_script.sh

0;root@17bdb693daac: /root@17bdb693daac:/# python
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
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/python3.6/dist-packages/tensorflow/__init__.py", line 101, i n <module>
    from tensorflow_core import *
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/__init__.py", line 4 0, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/__init__.py", line 50, in  __getattr__
    module = self._load()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/__init__.py", line 44, in  _load
    module = _importlib.import_module(self.__name__)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module           return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/__init__.py",  line 64, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/core/framework/graph _pb2.py", line 7, in <module>
    from google.protobuf import descriptor as _descriptor
ModuleNotFoundError: No module named 'google.protobuf'
>>> exit()
0;root@17bdb693daac: /root@17bdb693daac:/#

~It's always that Tensorflow lacks compatibility.~

I met the same issue and solved by reinstalling/upgrading the protobuf. I have installed the protobuf, google, google-cloud.

Was this page helpful?
0 / 5 - 0 ratings