解决:TypeError: Descriptors cannot not be created directly

我使用pip命令下载安装paddlepaddle库,具体命令如下所示,采用清华镜像源,这样下载速度更快!

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple paddlepaddle

安装完成后,我来在python文件中导入飞浆,输出其版本号,具体如下所示:

import paddle
print(paddle.__version__)

但是,PyCharm却报错,具体报错信息如下所示:

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

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

在PyCharm终端输入以下命令安装3.19.0版本的protobuf即可解决问题,具体代码如下所示:

pip install protobuf==3.19.0

下载完毕后即可正确输出paddle的版本!

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2023年9月15日
下一篇 2023年9月15日

相关推荐