在执行p4_toturials里的一些练习时,在执行第一个测试就出现了问题,首先是提示了如下错误:
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).
根据提示,应该是protoc的版本不对,这里说用版本为3.19.0的prootoc,解决方法如下:
在对应目录下执行
pip install protobuf==3.19.0
这样会自动卸载掉原来的protobuf,重新下载版本为3.19.0的protobuf,我的版本原来是4.21.4,版本过高,根据上面的提示(红色部分)也可以看出,需要降级,所以直接下载3.19.0版本即可。