【发布时间】:2018-11-20 17:02:41
【问题描述】:
我想使用已经在 Python 中 googleapis/api-common-protos 定义的 proto 文件。例如
syntax = "proto3";
package com.example.service.rev0;
import "google/protobuf/any.proto";
import "google/rpc/code.proto";
message GenericExcInfo {
google.rpc.Code status_code = 1;
string name = 2;
string message = 3;
repeated string stack_trace_entries = 4;
string code_filename = 5;
int32 code_lineno = 6;
string code_name = 7;
google.protobuf.Any arbitrary_info = 16;
}
如果安装了python包googleapis-common-protos,则相关的python模块(在本例中为google.rpc.code_pb2.Code)可用。但是由于没有安装 proto 文件,所以出现以下错误。
$ protoc --proto_path=. --python_out=. exc_info.proto
google/rpc/code.proto: File not found.
exc_info.proto: Import "google/rpc/code.proto" was not found or had errors.
exc_info.proto:14:5: "google.rpc.Code" is not defined.
如何在 Python 中使用这些 google proto 文件?我必须git clone repo 并在编译时包含每个 proto 文件吗?
【问题讨论】:
标签: python google-api protocol-buffers