Skip to content
Latchkey

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.

python
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

  1. Read which protobuf version the error or TF metadata requires.
  2. Pin protobuf to a version inside that range.
  3. Recompile the lockfile so the pin holds across CI.
Terminal
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.

Terminal
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

How 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.

Frequently asked questions

What causes "TensorFlow protobuf mismatch"?
A transitive dependency bumped protobuf above (or below) what this TF release pins, breaking the generated descriptor code.
How do I fix TensorFlow protobuf mismatch?
Pin protobuf into TensorFlow's supported range

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card