Descriptors cannot not be created directly.
时间: 2023-09-18 20:16:19 浏览: 70
"Descriptors cannot not be created directly"是一个报错信息,它意味着无法直接创建描述符。这个报错通常与使用过时的protobuf库或生成的代码相关。
解决这个问题的方法有以下几种:
1. 重新生成代码:如果报错信息中提到了"_pb2.py"文件,那么说明你的生成代码已经过时,需要使用protoc工具重新生成代码。确保你使用的protoc版本大于等于3.19.0。
2. 降级protobuf库:如果无法立即重新生成代码,你可以尝试降级protobuf库的版本到3.20.x或更低版本,这可能会解决兼容性问题。
3. 设置PYTHON_IMPLEMENTATION变量:另一个可能的解决方法是设置环境变量PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION为"python",但这将使用纯Python解析,速度会比较慢。
需要注意的是,建议首选的解决方法是重新生成代码,以确保使用最新版本的protobuf库和正确的代码生成。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Descriptors cannot not be created directly](https://blog.csdn.net/suiyingy/article/details/125218783)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [已解决TypeError: Descriptors cannot not be created directly.](https://blog.csdn.net/yuan2019035055/article/details/127300696)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]