1

I am trying to write a simple program using protobuf in python on MAC. But I am getting "no module named 'google'" error. I installed protobuf using 'brew install protobuf'.

Below are the files.

addressbook.proto:

syntax = "proto3";

package tutorial;

message Person {
  optional string name = 1;
  optional int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    optional string number = 1;
    optional PhoneType type = 2;
  }

  repeated PhoneNumber phones = 4;
}

message AddressBook {
  repeated Person people = 1;
}

I used protoc command as below to generate addressbook_pb2.py

protoc -I=. --python_out=. ./addressbook.proto --experimental_allow_proto3_optional

test.py:

import addressbook_pb2
import sys

def writeData():
    return

if __name__ == "__main__":
    writeData()

I am getting below error.

Traceback (most recent call last):
  File "/Users/ka/Desktop/proto_python/test.py", line 1, in <module>
    import addressbook_pb2
  File "/Users/ka/Desktop/proto_python/addressbook_pb2.py", line 5, in <module>
    from google.protobuf import descriptor as _descriptor
ModuleNotFoundError: No module named 'google'

Can some one please help me how to resolve this issue.

kadina
  • 5,042
  • 4
  • 42
  • 83
  • Does this answer your question? [ImportError: No module named google.protobuf](https://stackoverflow.com/questions/38680593/importerror-no-module-named-google-protobuf) – Gino Mempin Oct 17 '21 at 03:44

1 Answers1

-1

try with

pip install protobuf (or pip3 install...)

And if you don't even had pip installed then

sudo apt-get install python-pip  (or python3-pip)
angelo.mastro
  • 1,680
  • 17
  • 14