使用tensorbaoardx报错——Descriptors cannot not 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.

 

 

运行代码报错:

from tensorboardX import SummaryWriter

 

 

 

 

报错内容:

 

 

 

发生异常: TypeError
Descriptors cannot not 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).
 

 

 

 

 

 

=================================================

 

 

 

 

根据报错信息提供的链接:

https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

 

 

根据官方给出的资料,可以知道Google的序列化协议protobuf已经由版本3.20.1升级到4.21.6,一些需要调用旧版本protobuf的python库将出错,这种情况需要通过设置环境变量或者安装旧版本的protobuf来解决。

 

 

查看一下本地的protobuf版本:

pip list

 

显示:

 

 

大概率确定是安装的protobuf版本高了的问题,更新低版本的protobuf,具体操作:

pip install --upgrade protobuf==3.20.1

 

 

------------------------------------------------------

 

 

 

再次运行,不报错,成功解决。

 

posted on 2022-09-22 07:48  Angry_Panda  阅读(2206)  评论(0)    收藏  举报

导航