无意间我在我的 ubuntu vps 上更新了 protobuf。现在一些非常重要的Python脚本不再工作了。速度其实并不重要。我有两个解决方案:
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 包,不确定这就是前进的方向
或设置 PROTOCOL_BUFFERS_PYTHON_IMPLMENTATION=python - 但我在哪里设置它。在Python脚本中?
pip install protobuf==3.20.*
注意:上面的
*
不是字面意思,它被称为“通配符”。您可以根据需要在其中输入自己的号码,如 3.20.1
、3.20.5
等。
请参阅2022 年 5 月所做的更改了解背景信息。
我不鼓励使用
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
作为您的解决方案。但如果您想使用它,则需要在运行使用生成源(客户端和服务器,如果适用)的代码的环境中设置此环境变量(也可能export
?)。
有关上述更改,请参阅此线程。
这是
protobuf
发布。
如果你不想重新编译你的原型,你可能想尝试转向
3.20.1
,但意识到这已经是最后的结果了,你正在推迟不可避免的事情......
如果您愿意重新编译(并测试)您的原型,您应该考虑转向
4.20.x
。
我解决了这个问题,将 protobuf 降级到 3.19.0。