0

I am struggling to compile my .proto files to generate the gRPC stubs in Python.

My current working directory is ./predictor. I have a simulator.proto file in the ./proto folder.

The readme for the project I am working on says I should run

protoc -I ../proto/ --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ../proto/simulator.proto

This fails and gives me

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

I try it with python -m grpc_tools.protoc ... and it still doesn't work. I have double checked that I have grpc installed, I have reinstalled it with pip, and also git clone'd the grpc folder and built from the source. I am not sure what else to do. Does anyone have an idea?

Saagar
  • 3
  • 2

1 Answers1

0

You can't (easily!?) use protoc for Python and are best placed using the module as you describe.

The command should be similar to:

python \
-m grpc_tools.protoc \
--proto_path=../proto \
--python_out=. \
--grpc_python_out=. \
../proto/*.proto

Assuming that you have a parent directory called proto containing at least one .proto file and you run this command from python:

.
├── protos
│   └── x.proto
└── python
    ├── x_pb2_grpc.py
    └── x_pb2.py

What errors do you get when using the module?

DazWilkin
  • 32,823
  • 5
  • 47
  • 88
  • I get `RuntimeWarning: 'grpc_tools.protoc' found in sys.modules after import of package 'grpc_tools', but prior to execution of 'grpc_tools.protoc'; this may result in unpredictable behaviour warn(RuntimeWarning(msg)) Missing output directives.`. I don't the warning matters, but I think missing output directives is a problem. – Saagar Oct 20 '20 at 21:02
  • Running the command you sent generates the simulator_pb2.py file but it does not generate simulator_pb2_grpc.py – Saagar Oct 20 '20 at 21:10
  • Actually I think I got it now. I was missing one of the cli flag options. Thanks for the help! – Saagar Oct 20 '20 at 21:16