当使用从我们的 protobuf 类生成的 Python 代码时,我们得到这个错误:
cannot import name descriptor_pb2
等效的 C++ 生成代码工作得很好,所以看起来我们的实际原型定义没有问题。
当我尝试导入我们的类时会发生此错误,如下所示:
import sys
sys.path.append('..\path\to\generated')
sys.path.append('..\contrib\protobuf\python')
from foobar_pb2 import FooBar
附加系统路径是否正确?
我检查了protobuf\python\google\protobuf
目录descriptor_pb2.py
但只找到descriptor.py
了 - 我们使用的是最新版本,所以我假设我们没有丢失任何文件。
有谁知道解决方案是什么?