ImportError: cannot import name ‘builder‘ from ‘google.protobuf.internal‘ 报错分析与解决

文章讲述了在TensorBoard使用过程中遇到的protobuf版本相关问题,包括`Descriptorscannotbecreateddirectly`错误,解决方法是升级protobuf库至3.20.0或适当降级,并提供了相应的工作arounds。
摘要由CSDN通过智能技术生成

在TensorBoard使用结束,想要继续进行模型的训练、评估时,出现上面的问题。

【报错原因】

问题源自所用的google.protobuf版本过低。在更新的版本里,builder模块已经被迁移到了google.protobuf包内,不再位于google.protobuf.internal路径下。

【解决方案】

提升protobuf库的版本:

pip install --upgrade protobuf

【相关问题】TypeError: Descriptors cannot be created directly.

TypeError: Descriptors cannot be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

类型错误:描述符不能直接创建。 如果这个调用来自_pb2.py文件,你的生成代码已经过时,必须使用protoc >= 3.19.0重新生成。 如果你不能立即重新生成你的原型,其他可能的解决方法包括:

  1. 将protobuf包降级到3.20.x或更低版本。
  2. 设置环境变量PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python(但这将使用纯Python解析,速度会慢得多)。

【错误原因】

问题是由于使用了过高版本的protobuf库所导致的。在protobuf的更新版本中,为了提升性能,对Descriptor对象的生成机制进行了调整。

【解决方案】

pip uninstall protobuf        # 卸载原有protobuf库,[Y/n]时输入Y 
pip install protobuf==3.20.0

【注】这两个问题相互影响,经常一起出现 

  • 15
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值