已解决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: pycharmPyCharm Community Edition 2022.1.4inPaddleOCR-release-2.6PPOCRLabe1>-









报错代码



粉丝群一个小伙伴想要安装一个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: pycharmPyCharm Community Edition 2022.1.4inPaddleOCR-release-2.6PPOCRLabe1>-



报错翻译



报错信息翻译如下:

类型错误:无法直接创建描述符。 如果此调用来自_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:pycharmpycharm社区版2022.1.4inPidleOCR-release-2.6PPOCRabe1>



报错原因



报错原因:

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



解决方法



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

pip install protobuf==3.19.0

或者:

pip install protobuf~=3.19.0

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

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

    专栏福利:简历指导、招聘内推、每周送实体书、80G全栈学习视频、300本IT电子书:Python、Java、前端、大数据、数据库、算法、爬虫、数据分析、机器学习、面试题库等等 注意:如果希望得到及时回复,订阅专栏后私信博主进千人VIP答疑群
经验分享 程序员 微信小程序 职场和发展