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

2024-10-01 07:42:15 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

Tags: nofromimport消息grpcas错误google
1条回答
网友
1楼 · 发布于 2024-10-01 07:42:15

试图重现你的问题

我的配置也很好

看起来在pip中有multiple{}个包。
还有一个名为google的软件包实际上不是谷歌的官方软件包。
你用pip install 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.

相关问题 更多 >