grpc:从Maven将原型文件编译成python时,缺少grpc.py文件 [英] grpc: when compiling proto files into python from maven, grpc.py files are missing
问题描述
当我从python生成grpc文件时(运行python -m grpc_tools.protoc
),对于X个原型文件中的每个文件 X_pb2.py
,我都会得到2个文件和 X_pb2_grpc.py
.
When I generate grpc files from python (running python -m grpc_tools.protoc
), I get 2 files for each one of the X proto files, X_pb2.py
and X_pb2_grpc.py
.
但是,通过使用protobuf-maven-plugin(0.6.1)中的 compile-python maven目标,我只能得到X_pb2.py文件,而不是 grpc文件.我的问题是pb2.py文件中缺少服务.那么我该如何构建grpc.py文件呢?
However by using compile-python maven goal from protobuf-maven-plugin (0.6.1), I only get the X_pb2.py files and not the grpc files. The problem that I have with this is that the services are missing from the pb2.py files. So how can I get the grpc.py files to be built?
从点子列表中
grpcio 1.23.0
grpcio-tools 1.23.0
protobuf 3.9.1
$ python --version
Python 3.7.3
$ pip --version
pip 19.2.3 from /blahblahblah/lib/python3.7/site-packages/pip (python 3.7)
推荐答案
xolstice Maven插件似乎不具备开箱即用的功能.gRPC代码生成需要 protoc
编译器的插件.此插件被烘焙到PyPI上的 grpcio-tools
包中.您必须编译Python gRPC protoc
插件和
It doesn't look like the xolstice Maven plugin supports this out of the box. gRPC code generation requires a plugin to the protoc
compiler. This plugin is baked into the grpcio-tools
package on PyPI. You'll have to compile the Python gRPC protoc
plugin and supply it to protobuf-maven-plugin to make it work. The protocPlugin
parameter looks like it should do what you want.
但是在更高的层次上,您使用Maven来构建Python工件是有原因的吗?
But at a higher level, is there a reason why you're using Maven to build Python artifacts?
这篇关于grpc:从Maven将原型文件编译成python时,缺少grpc.py文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!