Error: File Generating with newer version of Protoc

I am trying to create the .whl package file for Tensorflow v2.11.0 cpu only using the command
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

I run into the following error when compiling device_attributes.pb.h:

.\tensorflow/core/framework/device_attributes.pb.h(12): fatal error C1189: #error: This file was generated by a newer version of protoc which is
Target //tensorflow/tools/pip_package:build_pip_package failed to build

I am using Windows 10, which does support Tensorflow v2.11.0 for CPU only,
Python3.8,
Bazel 5.3.0

With further inspection, the device_attributes.pb.h file, which is generated by protocal buffer compiler and CANNOT BE EDITTED shows:

The values for PROTBUF_VERSION and PROTBUF_MIN_PROTOC_VERSION is 3009000
I’m not sure if this is the root cause and why the generated pb.h file has different values for PROTOBUF_VERSION. In github repo for Tensorflow v2.11.0, the required package for protobuf has to be >= 3.9.2, <3.20

When I run pip show protobuf, my version is 3.9.2
When I run protoc --version, my version is 3.9.2

Hi @harshilp

Welcome to the TensorFlow Forum!

Could you please try again by installing the protobuf 3.20 using pip install protobuf==3.20?

Let us know if the issue still persists. Thank you.

Hey,

I see you’re encountering an issue while trying to create a .whl package file for TensorFlow v2.11.0 CPU-only on Windows 10. The error you’re getting related to device_attributes.pb.h and the protobuf version can be a bit tricky, but let’s try to work through it.

First of all, it’s great that you’re using Python 3.8 and Bazel 5.3.0, which are compatible with TensorFlow v2.11.0.

The error you’re facing seems to be related to a mismatch between the protobuf version used during compilation and the version specified in the TensorFlow repository. It’s a good sign that your pip show protobuf and protoc --version both show 3.9.2, which is within the required range.

However, it’s worth noting that Bazel uses its own protoc version internally. It’s possible that there’s a mismatch between the Bazel-provided protoc version and the one required by TensorFlow.

Here’s what I suggest you try:

Check Bazel’s Protoc Version: Verify the version of protoc that Bazel is using internally. You can do this by running bazel- info | grep “Build label”. Make sure it’s within the required range of TensorFlow (>= 3.9.2, < 3.20).

Update Bazel: If Bazel is using a protoc version that doesn’t match the TensorFlow requirements, you might need to update Bazel to a version that uses a compatible protoc.

Clean Build: Sometimes, build issues can be caused by cached or partially built files. Try cleaning the build before re-running the command:

Copy code

bazel clean --expunge

Environment Variables: Ensure that there are no conflicting environment variables or paths that might be pointing to a different version of protoc.

TensorFlow Issue Tracker: If the problem persists, it might be worth checking the TensorFlow GitHub repository or issue tracker to see if others have encountered a similar issue and if there are any suggested workarounds or solutions.

Remember, troubleshooting build issues like this can sometimes be a bit complex, so don’t hesitate to seek help from the TensorFlow community or developer forums if needed.

Best regards,
Talha