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

2024-04-26 06:05:14 发布

您现在位置:Python中文网/ 问答频道 /正文

正如问题所说,我从源代码处编译了grpc,并且也执行了sudo pip install grpcio,但是which grpc_python_plugin没有返回任何内容。这是一个问题,因为grpc python的route_指南示例要求我运行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.

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


Tags: 方法内容whichgrpc源代码sudonotout
3条回答
python -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. my_proto.proto

编辑:

显然,gRPC github网站上有关于这个问题的公开问题。Protoc似乎与grpc_python_plugin存在兼容性问题?我通过安装grpc_tools解决了这个问题,然后使用grpc_tools.protoc而不是protoc

$ pip install grpcio-tools
$ pip install googleapis-common-protos

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

见协议问题[791和4961]:

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

若要解决此错误,请确保系统上已安装grpc_python_plugin。 在python平台上pip install grpcio不安装特定于平台的插件,因此必须通过以下步骤分别安装它们

  • a) cd grpc(grpc存储库)
  • b) git submodule update --init
  • c) make grpc_python_plugin

这将为您构建grpcpython插件。现在,找出系统上grpc_python_plugin的位置,让我们称之为binary_path

如果二进制路径在$PATH环境变量(echo $PATH)下,则可以继续。但是,如果不在$PATH变量下,则有两个选项

run_codegen.sh更新为--plugin=protoc-gen-grpc=binary_path 或者,将二进制文件复制到$PATH环境变量跟踪的某个位置

相关问题 更多 >