天天看点

ubuntu安装protobuf

验证环境:ubuntu16.04

安装caffe1.0时,需要安装protobuf。否则报错:

google/protobuf/arena.h: No such file or directory           

或:

ImportError: No module named google.protobuf.internal           

以下几种方式供选择:

方法1-apt安装:

sudo apt-get install python-protobuf           

方法2-源码安装:

1、下载:

wget https://github.com/protocolbuffers/protobuf/tree/v3.16.0           

2、工具准备:

sudo apt-get install build-essential autoconf automake libtool curl make g++ unzip           

3、编译安装:

cd protobuf
./configure #  或者 ./configure --prefix=/usr // 前一种方式默认安装在/usr/local 后一种方式安装在 /usr (Linux默认路径)
make
make check # (可跳过)
sudo make install 
sudo ldconfig (刷新共享库缓存)           

1)一般直接进入protobuf主目录,并且./configue,但是有的版本没有./configue文件。需先安装aotomake,先用automaker生成configure文件:

./autogen.sh           

然后再./confiure。

2)protobuf安装时make check出错可以先不用管,暂时跳过,后期出错了再回来排查就好了。

查看安装是否成功:

protoc --version           

安装成功会显示版本信息,安装失败会提示错误信息。

4、编译protobuf的python接口:

cd python
python setup.py build
python setup.py test
python setup.py install           

在python中测试一下,如果import google.protobuf没有报错就可以用了。