Skip to content Skip to sidebar Skip to footer

Protocol Buffer Import Resolution

Before reading through this rather long question, I've raised a bug https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1103. The documentation for Proto Packages and

Solution 1:

as i was trying the same thing as you do, i came up with a possible solution using a Makefile to create the appropriate files. Because i was testing with python, i installed the grpc python package and used protoc through python instead of using it directly, but the input and outcome should be the same though.

General protobuf flags used in every protoc call:

GRPC_FLAGS := \
    -I. \
    -I/usr/local/include \
    -I$(GOPATH)/src \
    -I$(GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis

Source generation

Source code specific flags:

CLIENT_FLAGS := \
    --proto_path=./protos \       <-- This is where my *.proto live
    --python_out=grpctest/client \
    --grpc_python_out=grpctest/client

Call protoc to generate project specific protocol from your *.proto

python3 -m grpc_tools.protoc $(CLIENT_FLAGS) $(GRPC_FLAGS) protos/*.proto

Annotation generation

Annotation specific flags:

CLIENT_GW_FLAGS := \
    --python_out=grpctest/client \
    --grpc_python_out=grpctest/client

Call protoc to generate annotation specific files:

python3 -m grpc_tools.protoc $(CLIENT_GW_FLAGS) $(GRPC_FLAGS) google/api/annotations.proto
python3 -m grpc_tools.protoc $(CLIENT_GW_FLAGS) $(GRPC_FLAGS) google/api/http.proto

Final Filesystem Structure

├── client.py
├── config.yml
├── file
├── google
│   └── api
│       ├── __pycache__
│       ├── annotations_pb2.py
│       ├── annotations_pb2_grpc.py
│       ├── http_pb2.py
│       └── http_pb2_grpc.py
├── grpctest_pb2.py
└── grpctest_pb2_grpc.py

Solution 2:

Try this : pip install googleapis-common-protos. I encountered the same error and solved it using this method.


Post a Comment for "Protocol Buffer Import Resolution"