带有 grpc_python_plugin 的协议:google/protobuf/any.proto:找不到文件

Mar*_* Ou 4 protocol-buffers

我正在运行这个命令:

protoc protobuf/file.proto --proto_path=protobuf --proto_path=protobuf --python_out=out/builtin_pb --grpc_out=out/builtin_pb --plugin=protoc-gen-grpc=/usr/local/bin/grpc_python_plugin
Run Code Online (Sandbox Code Playgroud)

其中 file.proto 有:

syntax = "proto3";

import "google/protobuf/any.proto";
Run Code Online (Sandbox Code Playgroud)

还有类似的东西:

google.protobuf.Any arg = 3;
Run Code Online (Sandbox Code Playgroud)

但是,它有错误:

google/protobuf/any.proto: File not found.
bess_msg.proto: Import "google/protobuf/any.proto" was not found or had errors.
bess_msg.proto:251:3: "google.protobuf.Any" is not defined 
...
Run Code Online (Sandbox Code Playgroud)

我可以遵循哪些步骤来确保 any.proto 正确安装?

谢谢

小智 7

我在 Ubuntu 上尝试将 protobuf 编译为 python 时遇到此错误。我的问题是我已经使用安装了编译器sudo apt install protobuf-compiler,但没有使用安装资源sudo apt install libprotobuf-dev

感谢这个答案向我展示了我的方法的错误。