已解决TypeError: Descriptors cannot not be created directly.

Posted 袁袁袁袁满

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了已解决TypeError: Descriptors cannot not be created directly.相关的知识,希望对你有一定的参考价值。

已解决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>-





文章目录





报错代码



粉丝群一个小伙伴想要安装一个PPOCRLabel,pip里已经把paddlepaddle和paddleorc下好了,然后输入PPOCRLabel --lang ch
,但是还是发生了报错(当时他心里瞬间凉了一大截,跑来找我求助,然后顺利帮助他解决了,顺便记录一下希望可以帮助到更多遇到这个bug不会解决的小伙伴),报错代码如下:





报错信息内容如下

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'

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

千人全栈VIP答疑群联系博主帮忙解决报错

由于博主时间精力有限,每天私信人数太多,没办法每个粉丝都及时回复,所以优先回复VIP粉丝,可以通过订阅限时9.9付费专栏《100天精通Python从入门到就业》进入千人全栈VIP答疑群,获得优先解答机会(代码指导、远程服务),白嫖80G学习资料大礼包,专栏订阅地址:https://blog.csdn.net/yuan2019035055/category_11466020.html

  • 优点作者优先解答机会(代码指导、远程服务),群里大佬众多可以抱团取暖(大厂内推机会),此专栏文章是专门针对零基础和需要进阶提升的同学所准备的一套完整教学,从0到100的不断进阶深入,后续还有实战项目,轻松应对面试!

  • 专栏福利简历指导、招聘内推、每周送实体书、80G全栈学习视频、300本IT电子书:Python、Java、前端、大数据、数据库、算法、爬虫、数据分析、机器学习、面试题库等等

  • 注意:如果希望得到及时回复,订阅专栏后私信博主进千人VIP答疑群

免费资料获取,更多粉丝福利,关注下方公众号获取

TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file……

问题描述

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).

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

解决方案

pip uninstall protobuf
pip install protobuf==3.20.1

引用参考

https://github.com/protocolbuffers/protobuf/issues/10051

开发者涨薪指南 48位大咖的思考法则、工作方式、逻辑体系

以上是关于已解决TypeError: Descriptors cannot not be created directly.的主要内容,如果未能解决你的问题,请参考以下文章

webpack TypeError:无法读取未定义的属性“已解决”

[Ray.Tune] [已解决] TypeError: ray.cloudpickle.dumps

[Ray.Tune] [已解决] TypeError: ray.cloudpickle.dumps

我的Android进阶之旅解决错误:java.lang.RuntimeException: Not allowed to write file descriptors here

Python 错误:TypeError String Indices Must be Integers 已解决

已解决TypeError: search() got an unexpected keyword argument ‘requests_timeout’