Generating grpc stubs for Python from the command line

‹ Understanding protocol buffer version compatibility issues in Python | strace equivalent in Mac OS X ›

The GRPC quickstart guide refers to generating GRPC stubs using python code similar to

When you look in this file, you see what appears to be a command line like: protoc --python_out=. --grpc_python_out=. myfile.proto

However, if you actually try to execude that command line with either protoc 2.6.1 or 3.0.0, you get this error:

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

The solution is to make sure that the grpcio-tools python package is installed and use the command line in the tutorial instead: python -m --proto_path=. --python_out=. --grpc_python_out=. proto2.proto

As far as I am able to tell from the output, python -m is equivalent to protoc 3.0.0 in which case, if you want to use GRPC and python, you don't even need to have the protoc binary installed anywhere else anymore and just rely on the dynamic library version in grpcio-tools.

Subscribe to All Posts - Wesley Tanaka