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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →