0

I'm trying to use gRPC to access to google home graph api. in this tutorial I've found an example on how to compile a proto file to get some python code that can be used by a client. The provided example generate some python files but they are not usable because they seems to import other files that do not exist.

The command I've used to compile is the following: python -m grpc_tools.protoc -I./googleapis --python_out=. --grpc_python_out=. googleapis/google/home/graph/v1/homegraph.proto to compile this proto file

when I try to import the generated file I got the following error.

(grpc_test) ➜  grpc_test git:(master) ✗ python test.py
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import google.home.graph.v1.homegraph_pb2 as home_graph
  File "/home/corsair/code/grpc_test/google/home/graph/v1/homegraph_pb2.py", line 16, in <module>
    from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2
ModuleNotFoundError: No module named 'google.api'

It's clear that some other files are expected to exist.

Is there a way to automatically compile also all the dependencies of the proto I need?

cunfusu
  • 97
  • 1
  • 9

1 Answers1

0

There is a compiled common ProtoBuf library for Google APIs: https://pypi.org/project/googleapis-common-protos/.

pip install googleapis-common-protos

After installing this package, the import error should go away.

Lidi Zheng
  • 1,801
  • 8
  • 13