关于“Couldn't build proto file into descriptor pool!”的解决办法

上周上线一个小东西,结果报异常:

TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "member.proto":
    get_info_request.member_id: "get_info_request.member_id" is already defined in file "post.proto".
    get_info_request: "get_info_request" is already defined in file "post.proto".
    get_info_reply: "get_info_reply" is already defined in file "post.proto".
    Member.get_info: "get_info_request" seems to be defined in "post.proto", which is not imported by "member.proto".  To use it here, please add the necessary import.
    Member.get_info: "get_info_reply" seems to be defined in "post.proto", which is not imported by "member.proto".  To use it here, please add the necessary import.

在 Windows 开发,生产环境为 Debian 8.0 。


从异常内容来看,是因为 member.proto 中定义的 get_info_request.member_id、get_info_request 和 get_info_reply 在 post.proto 中已经定义,member.proto 中没有指定导入(包)导致描述冲突。


解决问题的方式很简单,就是在发生定义冲突的 .proto 文件中添加对应的包导入声明:

package pb.post_pb2;

重新编译 .proto 文件,运行正常。