已解决If this call came from a _pb2.py file, your generated code is out of date and must be regenerated

发布时间 2023-05-19 21:26:38作者: 咖啡陪你

已解决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.1.0If 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_BUPFERS_PYTHON_iMPLEMENTATION=python (but this will use pure-Python parsing and will be mch slower ,More information: https://developers. google.com/protocol-buffers/docs/news/2022-05-06#python-updates
(paddle) F: \pycharm\PyCharm Community Edition 2022.1.4\bin\PaddleOCR-release-2.6\PPOCRLabe1>-

 

报错代码

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.1.0If 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_BUPFERS_PYTHON_iMPLEMENTATION=python (but this will use pure-Python parsing and will be mch slower ,More information: https://developers. google.com/protocol-buffers/docs/news/2022-05-06#python-updates
(paddle) F: \pycharm\PyCharm Community Edition 2022.1.4\bin\PaddleOCR-release-2.6\PPOCRLabe1>-

报错翻译

报错信息翻译如下:

类型错误:无法直接创建描述符。
如果此调用来自_pb2.py文件,则生成的代码已过期,必须使用protoc>=3.1.0重新生成。如果无法立即重新生成protos,则其他一些可能的解决方法如下:

将protobuf包降级至3.20.x或更低。
设置PROTOCOL_BUPFERS_PYTHON_iMPLEMENTATION=PYTHON(但这将使用纯PYTHON解析,速度会慢很多,更多信息:https://developers.google.com/protocolbuffers/docs/news/2022-05-06#python更新(桨板)F:\pycharm\pycharm社区版2022.1.4\bin\PidleOCR-release-2.6\PPOCRabe1>

报错原因:

仔细阅读报错信息就会发现,报错的主要原因是因为protobuf的版本太高而导致编译错误,所以我们只需要按照编译器提示的信息下载3.19.0对应的版本即可解决问题。小伙伴按下面的代码安装指定版本即可!!!

 

解决方法

执行下面的pip安装命令即可:

pip install protobuf==3.19.0

或者:

pip install 'protobuf~=3.19.0'

以上是此问题报错原因的解决方法,欢迎评论区留言讨论是否能解决,如果有用欢迎点赞收藏文章谢谢支持,博主才有动力持续记录遇到的问题!!!