使用清华源进行安装
pip3 install https://pypi.tuna.tsinghua.edu.cn/simple grpcio grpcio-tools protobuf坑:根据.proto文件转化时报错,但grpc-tools安装成功了
Error while finding module specification for 'grpc_tools.protoc' (ModuleNotFoundError: No module named 'grpc_tools')解决:
应该安装grpcio-tools,安装grpcio-tools时有的会报错
需要设置信任源即可:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn grpcio-tools2、编写proto配置文件
syntax = "proto3";
package format;
message Request {
string id = 1;
string data = 2;
}
message Response {
int32 code = 1;
string id = 2;
string data = 3;
}
3、自动生成代码
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. format.proto4、应用



