可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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]: