Help: p4types_pb2 and google.rpc import errors in Python gRPC controller

Hi everyone,

I’m trying to get a Python-based P4Runtime controller working with a Tofino switch, but I’m running into a couple of import errors when using the generated protobuf files. I’ve already generated the bindings using grpc_tools.protoc, but I’m still getting these issues:

Error 1:

ModuleNotFoundError: No module named ‘google.rpc’

I saw that p4runtime.proto imports google/rpc/status.proto, so I tried installing googleapis-common-protos, but I’m not sure if that’s the right fix or if I need to compile status.proto myself.

Error 2:

ImportError: cannot import name ‘p4types_pb2’ from ‘p4.config.v1’

From what I can tell, p4info.proto imports p4types.proto, but I only compiled p4info.proto and p4runtime.proto. Do I need to compile all of them together? If so, which .proto files exactly should I include in the command?

Here’s what I’m currently running:

python3 -m grpc_tools.protoc
-I./p4runtime/proto
-I./p4runtime/googleapis
–python_out=.
–grpc_python_out=.
p4runtime/proto/p4/v1/p4runtime.proto
p4runtime/proto/p4/config/v1/p4info.proto

Would appreciate any guidance or a working example if someone has it.

Thanks in advance.