TensorFlow protobuf version conflict in CI
Another dependency pulled a protobuf version outside the range TensorFlow supports. The generated TF protobuf code then fails at import, classically with "Descriptors cannot be created directly" when protobuf was upgraded past what the build expects.
What this error means
Importing tensorflow fails with "TypeError: Descriptors cannot be created directly" or "AttributeError: module 'google.protobuf...' has no attribute" naming a protobuf incompatibility.
TypeError: Descriptors cannot 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.Common causes
protobuf upgraded beyond TensorFlow's supported range
A transitive dependency bumped protobuf above (or below) what this TF release pins, breaking the generated descriptor code.
Two packages disagree on protobuf
TF and another library (grpcio, a cloud SDK) demand different protobuf majors, and the resolver picked one TF cannot use.
How to fix it
Pin protobuf into TensorFlow's supported range
- Read which protobuf version the error or TF metadata requires.
- Pin protobuf to a version inside that range.
- Recompile the lockfile so the pin holds across CI.
pip install "protobuf>=3.20.3,<5"Set the pure-Python protobuf fallback as a stopgap
As a temporary unblock, the pure-Python implementation avoids the C-descriptor mismatch, at a performance cost.
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=pythonHow to prevent it
- Constrain protobuf to TensorFlow's supported range in your lockfile.
- Upgrade TF and protobuf-dependent packages together.
- Compile a lockfile so the protobuf version is fixed before CI.