Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 288
Sid Shukla Avatar asked Jan 11 '16 03:01

Sid Shukla


2 Answers

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]:

  • https://github.com/google/protobuf/issues/791
  • https://github.com/grpc/grpc/issues/4961
like image 72
nikk Avatar answered Oct 30 '22 13:10

nikk


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

like image 33
Harsha Rastogi Avatar answered Oct 30 '22 14:10

Harsha Rastogi