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

12,581

Solution 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/.

Solution 2

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

Solution 3

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

Solution 4

the python's gRPC plugin for protoc is not installed by default

$ protoc -I=grpc/protos helloworld.proto --plugin=grpc_python_plugin --python_out=grpc/helloworld --grpc_python_out=grpc/helloworld
protoc-gen-grpc_pythong is not recognized as an internal or external command,
operable program or batch file.
--grpc_python_out: protoc-gen-grpc_python: Plugin failed with status code 1.

install protoc-gen-grpclib_python and protoc-gen-python_grpc

$ pip install grpclib protobuf

generate your python gRPC stubs (replace --grpc_python_out with --grpclib_python_out)

$ protoc -I=grpc/protos helloworld.proto --plugin=grpc_python_plugin --python_out=grpc/helloworld --grpclib_python_out=grpc/helloworld
Share:
12,581
Sid Shukla
Author by

Sid Shukla

Learner, Explorer, and Software Engineer

Updated on June 17, 2022

Comments

  • Sid Shukla
    Sid Shukla almost 2 years

    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.