Python grpc protobuf stubs generation issue: --grpc_out: protoc-gen-grpc: Plugin failed with status code 1

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

As the question says, I compiled grpc from source and also did sudo pip install grpcio, however, the which grpc_python_plugin doesn't return anything. This is a problem because the grpc python example for route_guide requires me to run protoc -I . --python_out=. --grpc_out=. --plugin=protoc-gen-grpc='which grpc_python_plugin' ./route_guide.proto in order to generate the python stubs. Since, which grpc_python_plugin doesn't return anything, I get the following error:

: program not found or is not executable --grpc_out: protoc-gen-grpc: Plugin failed with status code 1. 

If I shorten the command I'm trying to run to:protoc -I . --python_out=. ./route_guide.proto, it generates the route_guide_pb2.py file but without the Servicer and Stub classes, and server and stub methods. Ofc, these methods are necessary if one wants to use grpc for any purpose. Any help would be appreciated.

回答1:

It sounds like you don't have /usr/local/bin in your PATH; make install uses a prefix of /usr/local by default. Alternatively, after compilation grpc_python_plugin should be in bins/opt/.



回答2:

To resolve this error make sure you have grpc_python_plugin installed on your system. On python platforms pip install grpcio doesn't install platform specific plugins, so you have to install them separately by taking following steps

  • a) cd grpc (grpc repository)
  • b) git submodule update --init
  • c) make grpc_python_plugin

This will build the grpc python plugin for you. Now, find out the location of grpc_python_plugin on your system, lets call it binary_path

If binary_path is under $PATH environment variable (echo $PATH), you are good to go. However, if it is not under $PATH variable, you have two options

Update run_codegen.sh to --plugin=protoc-gen-grpc=binary_path or, copy the binary to one of the locations tracked by $PATH environment variable



回答3:

python -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. my_proto.proto 

Edited:

Apparently, there is open Issue on gRPC github site regarding this problem. Protoc seems to have a compatibility issue with grpc_python_plugin? I solved this problem by installing grpc_tools, then used grpc_tools.protoc instead of protoc.

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

Useful python tutorial: https://grpc.io/docs/tutorials/basic/python.html

See Protoc Issues [791 and 4961]:



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!