您的位置:首页 > 运维架构 > Linux

CentOS6.5下python版本的protobuf编译及安装

2016-11-03 17:40 856 查看
因为要学习faster r-cnn,在搭建环境的时,发现原本通过yum安装的protobuf没有安装python版本以及其他一系列版本版本兼容性问题,导致我必须用编译方式重新安装protobuf2.5

下载源码

首先,从github上下载protobuf的源码,地址:https://github.com/google/protobuf,我选择下载2.5.0版本。

编译protobuf

然后将下载的压缩包解压缩

unzip protobuf-2.5.0.zip


按照网上教程,应该执行
./configure
了,但是根目录下居然没有configure文件,却有一个autogen.sh,原来是因为protobuf的编译方式做了修改,要执行autogen.sh才会生成configure脚本。

但在执行autogen.sh时出错了,因为google.com被墙了,我的虚拟机里无法下载gtest,于是手动下载googletest-release-1.5.0.zip,解压缩后,改名为gtest放在protobuf-2.5.0目录下



autogen.sh代码片段

# Check that gtest is present.  Usually it is already there since the
# directory is set up as an SVN external.
# 判断是否存在gtest目录
if test ! -e gtest; then
echo "Google Test not present.  Fetching gtest-1.5.0 from the web..."
#如果目录不存在则尝试从google.com下载并解压缩,如果google被墙则下载失败
curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
#将解压缩后的目录改名为gtest
mv gtest-1.5.0 gtest
fi


googletest1.5.0下载地址:https://github.com/google/googletest/tree/release-1.5.0

#解压缩
unzip gtest-1.5.0.zip
mv gtest-1.5.0 gtest


执行protobuf编译

#执行autogen.sh生成configure
./autogen.sh
./configure
# -j8 多线程编译
make -j8
make check
# 安装编译成功的protobuf
sudo make install


安装python模块

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


验证Python模块

验证Python模块是否被正确安装

如果没有报错,说明安装正常。

$ python
>>> import google.protobuf.internal
>>>


参考:

http://www.cnblogs.com/chegnshi-coding/p/4457738.html

http://blog.csdn.net/wutbiao/article/details/45029779
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python centos protobuf gtest