Reputation: 732
By accident I updated protobuf
on my Ubuntu vps. Now some very essential Python scripts don't work anymore. Speed isn't really important. I got two solutions:
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).
Downgrade the protobuf
package, not sure it that's the way forward
or Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
- but where do I set this. In the python script?
Upvotes: 32
Views: 122640
Reputation: 974
pip install protobuf==3.20.*
Note: the *
above is not to be taken literally, it's called a "wildcard". You put your own number in there as needed, as in 3.20.1
, 3.20.5
, etc.
This is similar to TypeError: Descriptors cannot not be created directly
Upvotes: 59
Reputation: 40061
See Changes made in May, 2022 for background.
I'd discourage using PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
as your solution. But if you want to use it, you would need to set this environment variable (and possibly export
it too?) in the environment where you're running code that uses the generated sources (both client and server if applicable).
See this thread about the above change.
Here's the protobuf
releases.
If you don't want to recompile your protos, you may want to try moving to 3.20.1
but realize this is the end of the line and you're delaying the inevitable...
If you're willing to recompile (and test) your protos, you should consider moving to 4.20.x
.
Upvotes: 2