微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

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

解决方法

试图重现您的问题。

在我的配置中,一切都很好。

好像google中有multiple pip个软件包。
还有一个名为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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。