TensorFlow protobuf version mismatch

Viewed 14778

I've install TensorFlow via virtualenv. And it works well.

Now I want to load model using C++ and do prediction. But I fail to compile my program because of protobuf version mismatch. Error like:

tensorflow/core/framework/device_attributes.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
 #error This file was generated by an older version of protoc which is
  ^
tensorflow/core/framework/device_attributes.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
 #error incompatible with your Protocol Buffer headers.  Please
  ^
tensorflow/core/framework/device_attributes.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
 #error regenerate this file with a newer version of protoc.

In virtualenv:

$ pip show protobuf
Name: protobuf
Version: 3.4.0
Summary: Protocol Buffers

And in shell:

$ protoc --version
libprotoc 3.4.0

I used to have protobuf-2.6.1 in my environment but now upgrade to 3.4.0.

ubuntu 16.04

3 Answers

Please use the same version with tensorflow to recompile your proto files. You will find it in tensorflow/tensorflow/contrib/makefile/gen/protobuf/bin/protoc if you build tensorflow from source using build_all_linux.sh.

Had a similar issue which I struggled to resolve: compile script was always able to find an outdated version of protoc somewhere.

Checking protoc location:

which protoc # /usr/bin/protoc
sudo apt-get uninstall protobuf-compiler
conda uninstall protobuf
conda uninstall libprotobuf
exit # resign in

which means that there is a protoc binary /usr/bin/protoc and header files here /usr/include/google/protoc. Removing protoc installation would not necessarily remove header files inside include folder which would cause error to reappers. If you keep seeing the error after installing protobuf try cleaning include files for each protobuf locaiton.

After that feel free to download a compiled binary for your platform (in my case it was protoc-3.10.1-linux-x86_64.zip) and place it to a convenient location:

mkdir ~/tmp/
cd ~/tmp
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/protoc-3.10.1-linux-x86_64.zip
sudo rm -rf ./protoc
unzip protoc-3.10.1-linux-x86_64.zip -d protoc
chmod 755 -R protoc
BASE=/usr/local
sudo rm -rf $BASE/include/google/protobuf/
sudo cp protoc/bin/protoc $BASE/bin 
sudo cp -R protoc/include/* $BASE/include 

Despite seeing both"your protobuf version is older" and "your protobuf version is newer" during resolving the issue, simply latest version of protoc worked.

Related