TypeError: Descriptors cannot not be created directly.

请教下:出现这个问题怎么办,
我python从3.7到3.10全装过一边了还是有这个问题。
我也按照网上的方法pip uninstall protobuf和pip install protobuf==3.19.0也还是有下面的错误。

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 库有关。首先建议您确认一下您使用的 protobuf 库的版本是否符合要求。如果您已经尝试了 pip uninstall 和 pip install 命令,但仍然无法解决问题,可以尝试以下方法:

确认您生成的代码对应的 protobuf 版本和您安装的版本是否一致。如果不一致,可以尝试更新或降级 protobuf 库,或者重新生成protobuf代码。

如果您的代码中使用了 from tensorflow.core.protobuf import xxx 的形式导入 protobuf 模块,可以尝试使用 from google.protobuf import xxx 来替换它,因为从 3.9 版本开始,TensorFlow 已经摆脱了 protobuf 3.9.2 版本的依赖。

如果您在使用 Python 3.10,可以尝试切换回较早的 Python 版本,因为一些第三方库可能还不支持 Python 3.10。

希望这些方法能够对您有所帮助。如果以上方法仍然无法解决问题,建议您提供更详细的错误信息和代码片段,以便更好地定位问题。