使用 Python 在 gRPC 框架中导入已编译的 protobuf 时出错

Error in importing compiled protobuf in gRPC framework with Python

我用 gRPC 写了一个服务。当我启动服务时,它无法导入已编译的 protobuf 并显示以下错误消息:

from google.protobuf import descriptor as _descriptortitus| ModuleNotFoundError: No module named 'google'

已尝试重现您的问题。

而且我的配置都很好。

pip.
中似乎有 google 个包 还有一个名为 google 实际上不是官方 google 的包。
您是否使用 pip install google 安装了 google 软件包?

我是这样做的

pip install protobuf
pip freeze
protobuf==3.13.0
six==1.15.0
from google.protobuf import descriptor
dir(descriptor)
['Descriptor', 'DescriptorBase', 'DescriptorMetaclass', 'EnumDescriptor', 'EnumValueDescriptor', 'Error', 'FieldDescriptor', 'FileDescriptor', 'MakeDescriptor', 'MethodDescriptor', 'OneofDescriptor', 'ServiceDescriptor', 'TypeTransformationError', '_Deprecated', '_Lock', '_NestedDescriptorBase', '_OptionsOrNone', '_ParseOptions', '_ToCamelCase', '_ToJsonName', '_USE_C_DESCRIPTORS', '__author__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_internal_create_key', '_lock', '_message', 'api_implementation', 'binascii', 'os', 'six', 'threading', 'warnings']

我的python版本是

Python 3.6.7 (default, Dec  5 2018, 15:02:05) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.