编译caffe时关于protobuf版本不同的问题

首先安装caffe的时候Python的版本可选系统自带的Python2.7或者Python3.5,也可以使用anaconda中的Python版本,对应的Makefile.config中的Python路径对应的改变。

安装protobuf的方法也有好几种:

sudo apt-get install libprotobuf-dev protobuf-compiler  #Linux系统级的安装
sudo pip install google protocol  #python2.7版本的安装
sudo pip3 install google protocol  #python3.5版本的安装
conda install protobuf  #anaconda版本的安装

查看系统中已安装的protobuf:

whereis protoc  #查看那些路径下安装了protobuf
which protoc  #查看默认选用的protobuf
protoc --version  #查看当前默认的protobuf的版本
sudo protoc --version  #查看系统的protobuf的版本

所以在编译caffe如果报的错关于Google或者protobuf的,例如:

.build_release/src/caffe/proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is  
error: #error incompatible with your Protocol Buffer headers. Please update  
ImportError: No module named 'google'
问题往往存在于系统上存在多个protobuf的版本,而系统默认的版本不能满足编译caffe的要求,这个时候我们可以修改makefile文件的这两行,改为自己希望用的版本目录,例如改为使用系统的:
$(Q)protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<
$(Q)protoc --proto_path=$(PROTO_SRC_DIR) --python_out=$(PY_PROTO_BUILD_DIR) $<
改为
$(Q)/usr/bin/protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<
$(Q)/usr/bin/protoc --proto_path=$(PROTO_SRC_DIR) --python_out=$(PY_PROTO_BUILD_DIR) $<


猜你喜欢

转载自blog.csdn.net/m0_38082419/article/details/80117132
今日推荐