Python grpc protobuf 存根生成问题:--grpc_out:protoc-gen-grpc:插件失败,状态代码为 1

Sid*_*kla 6 python protocol-buffers grpc

正如问题所说,我从源代码编译了 grpc 并且也做了sudo pip install grpcio,但是,which grpc_python_plugin没有返回任何东西。这是一个问题,因为 route_guide 的 grpc python 示例要求我运行protoc -I . --python_out=. --grpc_out=. --plugin=protoc-gen-grpc='which grpc_python_plugin' ./route_guide.proto 以生成 python 存根。由于which grpc_python_plugin不返回任何内容,因此出现以下错误:

: program not found or is not executable
--grpc_out: protoc-gen-grpc: Plugin failed with status code 1.
Run Code Online (Sandbox Code Playgroud)

如果我缩短我尝试运行的命令:protoc -I . --python_out=. ./route_guide.proto,它会生成 route_guide_pb2.py 文件,但没有 Servicer 和 Stub 类,以及 server 和 stub 方法。Ofc,如果想将 grpc 用于任何目的,这些方法是必要的。任何帮助,将不胜感激。

nik*_*ikk 7

python -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. my_proto.proto
Run Code Online (Sandbox Code Playgroud)

编辑:

显然,gRPC github 站点上有关于此问题的公开问题。Protoc似乎有兼容性问题grpc_python_plugin?我通过安装解决了这个问题grpc_tools,然后用来grpc_tools.protoc代替protoc。

$ pip install grpcio-tools
$ pip install googleapis-common-protos
Run Code Online (Sandbox Code Playgroud)

有用的python教程:https : //grpc.io/docs/tutorials/basic/python.html

参见协议问题 [791 和 4961]:

  • 这个答案对我有帮助的操作部分是安装“googleapis-common-protos”,它允许我使用“grpc_tools.protoc” (2认同)

Eri*_*son 2

/usr/local/bin听起来你的 ;中没有PATH;make install默认情况下使用前缀/usr/local。或者,编译后grpc_python_plugin应该在bins/opt/.