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). More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
于 2022-12-20 20:56:05 首次发布
<div class="operating">
<a class="href-article-edit slide-toggle">版权</a>
</div>
</div>
</div>
</div>
<div id="blogColumnPayAdvert">
<div class="column-group">
<div class="column-group-item column-group0 column-group-item-one">
<div class="item-l">
<a class="item-target" href="https://blog.youkuaiyun.com/yuan2019035055/category_11680720.html" target="_blank" title="《告别Bug》" data-report-click="{"spm":"1001.2101.3001.6332"}">
<img class="item-target" src="https://img-blog.csdnimg.cn/89b3a0ad797b4684b2aac41c116d3308.png?x-oss-process=image/resize,m_fixed,h_224,w_224" alt="">
<span class="title item-target">
<span>
<span class="tit">《告别Bug》</span>
<span class="dec">专栏收录该内容</span>
</span>
</span>
</a>
</div>
<div class="item-m">
<span>536 篇文章</span>
<span>783 订阅</span>
</div>
<div class="item-r">
<a class="item-target article-column-bt articleColumnFreeBt" data-id="11680720">订阅专栏</a>
</div>
</div>
</div>
</div>
<article class="baidu_pl">
<div id="article_content" class="article_content clearfix">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-044f2cf1dc.css">
<div id="content_views" class="markdown_views prism-atom-one-dark">
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
</svg>
<p><mark>已解决TypeError: Descriptors cannot not be created directly.<br> 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:</mark><br> <mark>1. Downgrade the protobuf package to 3.20.x or lower.<br> 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<br> (paddle) F: \pycharm\PyCharm Community Edition 2022.1.4\bin\PaddleOCR-release-2.6\PPOCRLabe1>-</mark></p>
报错代码
粉丝群一个小伙伴想要安装一个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>-
- 1
- 2
- 3
- 4
- 5
报错翻译
报错信息翻译如下:
类型错误:无法直接创建描述符。
如果此调用来自_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
- 1
或者:
pip install 'protobuf~=3.19.0'
- 1
以上是此问题报错原因的解决方法,欢迎评论区留言讨论是否能解决,如果有用欢迎点赞收藏文章谢谢支持,博主才有动力持续记录遇到的问题!!!