centos6.5安装tensorflow

安装前提

1.       TensorFlow只支持64位平台

2.       Centos6.5默认安装的python是2.6版本的,TensorFlow要求是2.7.x或3.x

3.       需要用pip3进行安装,pip不行

4.       由于GFW,需要更改pip源为国内源

5.       Centos6.5的glibc库版本最高为2.14,但是tensorflow需要glibc库版本为2.16,需要手动升级,为了不必要的麻烦,可以选用更高版本的操作系统安装tensorflow

安装步骤

更新python版本

Centos6.5默认安装的python版本为2.6.6,需要将其升级至python3,这里选择安装python3.6.4

从官网https://www.python.org/downloads/source/下载python安装包,这里选择较新的版本python3.6.4

上传和解压

[root@slave1tensorflow]# tar -xf Python-3.6.4.tar.xz

安装必须要的依赖

在编译之前需要安装一些必须的依赖,否则当报错的时候还得重新编译

 [root@slave1tensorflow]# yum install openssl-devel -y

 [root@slave1tensorflow]# yum install zlib-devel  -y

编译安装

[root@slave1Python-3.6.4]# cd Python-3.6.4

[root@slave1Python-3.6.4]# ./configure --prefix=/opt/Python     #安装目录可以自己定义无所谓。

[root@slave1Python-3.6.4]#make && make install

[root@slave1Python-3.6.4]# ln-s /opt/Python/bin/python3 /usr/bin/python3

输入python3进行版本验证:

[root@slave1tensorflow]#python3

Python3.6.4 (default, Jan 19 2018, 14:37:12)

[GCC4.4.7 20120313 (Red Hat 4.4.7-4)] on linux

Type"help", "copyright", "credits" or"license" for more information.

更新pip至pip3

   安装setuptools

可通过官方模板库进行下载:https://pypi.python.org/pypi,这里选择wget进行下载:

 [root@slave1 tensorflow]# wget--no-check-certificate  https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26

[root@slave1tensorflow]# tar -zxvf setuptools-19.6.tar.gz

[root@slave1setuptools-19.6]# cd setuptools-19.6

[root@slave1setuptools-19.6]# python3 setup.py build

[root@slave1setuptools-19.6]# python3 setup.py install

    安装pip3

[root@slave1tensorflow]# wget --no-check-certificate  https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb

tar-zxvf pip-8.0.2.tar.gz

[root@slave1tensorflow]# cd pip-8.0.2

[root@slave1pip-8.0.2]# python3 setup.py build

[root@slave1pip-8.0.2]# python3 setup.py install

[root@slave1pip-8.0.2]# ls /opt/Python/bin/

[root@slave1 tensorflow]# ln -s /opt/Python/bin/pip3 /usr/bin/pip3

 

[root@slave1tensorflow]# pip3 -V 

 

更新pip源至国内

[root@slave1home] mkdir -p ~/.pip

创建配置文件:

[root@slave1home] vim  ~/.pip/pip.conf

[global]

index-url= http://mirrors.aliyun.com/pypi/simple/

[install]

trusted-host=mirrors.aliyun.com

其他国内源地址如下:

  中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

  豆瓣(douban) http://pypi.douban.com/simple/

  清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

  中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

现在使用pip安装组件就可以体会到飞一般的速度了。

如果是临时使用国内地址可以在安装组件的时候加参数-i

pipinstall nose -i http://mirrors.aliyun.com/pypi/simple

安装TensorFlow

  [root@slave1 tensorflow]# pip3 installtensorflow

Collectingtensorflow

  Couldnot find a version that satisfies the requirement tensorflow (from versions: )

Nomatching distribution found for tensorflow

Youare using pip version 8.0.2, however version 9.0.1 is available.

Youshould consider upgrading via the 'pip install --upgrade pip' command.

发现pip3版本过低,需要对pip3版本进行更新,如下:

[root@slave1tensorflow]# pip3 install --upgrade pip

 

[root@slave1tensorflow]# pip3 install tensorflow

至此,Centos6.5安装tensorflow成功!

 

 

 

 

报错指南

GLIBC_2.16 not found

现象

运行import tensorflow as tf报错:

ImportError: /lib64/libc.so.6: version `GLIBC_2.16'not found (required by/opt/Python/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

出现原因

Centos6.5的GLIBC版本太低,最高为2.14,不满足tensorflow的要求,需要再安装GLIBC_2.16

解决办法

安装GLIBC_2.17

 

yum install gcc

 

wget http://ftp.gnu.org/pub/gnu/glibc/glibc-2.17.tar.gz

tar -zxvf glibc-2.17.tar.gz

cd glibc-2.17

mkdir build

cd build

../configure --prefix=/usr --disable-profile--enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin 

make && make install

需要等大概10分钟。

 

输入strings /lib64/libc.so.6|grep GLIBC发现已经更新

GLIBC_2.2.5

GLIBC_2.2.6

GLIBC_2.3

GLIBC_2.3.2

GLIBC_2.3.3

GLIBC_2.3.4

GLIBC_2.4

GLIBC_2.5

GLIBC_2.6

GLIBC_2.7

GLIBC_2.8

GLIBC_2.9

GLIBC_2.10

GLIBC_2.11

GLIBC_2.12

GLIBC_2.13

GLIBC_2.14

GLIBC_2.15

GLIBC_2.16

GLIBC_2.17

GLIBC_PRIVATE

参考资料

http://blog.csdn.net/levy_cui/article/details/51251095

CXXABI_1.3.7 not found

现象

Python3中运行import tensorflowas tf报错:

ImportError: /usr/lib64/libstdc++.so.6: version`CXXABI_1.3.7' not found (required by /opt/Python/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

出现原因

升级gcc时,生成的动态库没有替换老版本gcc的动态库

解决办法

在系统中找到高版本的CXXABI库,并替换。

1.        查找系统CXXABI的版本

strings /lib64/libc.so.6|grep CXXABI

2.        查找编译gcc时生成的最新动态库:

[root@slave1 tensorflow]# find / -name"libstdc++.so.*"

/opt/cloudera/parcels/CDH-5.7.0-1.cdh5.7.0.p0.45/lib/impala/lib/libstdc++.so.6.0.20

/opt/cloudera/parcels/CDH-5.7.0-1.cdh5.7.0.p0.45/lib/impala/lib/libstdc++.so.6

/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.13-gdb.pyc

/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.13-gdb.pyo

/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.13-gdb.py

/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.13-gdb.pyc

/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.13-gdb.pyo

/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.13-gdb.py

/usr/lib64/libstdc++.so.6.0.20

/usr/lib64/libstdc++.so.6.0.13

/usr/lib64/libstdc++.so.6

/usr/lib64/libstdc++.so.6.bak

3.        将新版本的动态库复制到/usr/lib64/中

cp/opt/cloudera/parcels/CDH-5.7.0-1.cdh5.7.0.p0.45/lib/impala/lib/libstdc++.so.6.0.20/usr/lib64/

4.        重新创建软连接

cd /usr/lib64/

mv libstdc++.so.6 libstdc++.so.6.bak

ln -s libstdc++.so.6.0.20 libstdc++.so.6

[root@slave1 lib64]# strings/usr/lib64/libstdc++.so.6 | grep 'CXXABI'

CXXABI_1.3

CXXABI_1.3.1

CXXABI_1.3.2

CXXABI_1.3.3

CXXABI_1.3.4

CXXABI_1.3.5

CXXABI_1.3.6

CXXABI_1.3.7

CXXABI_1.3.8

CXXABI_TM_1

至此,解决完成

 

参考资料:http://blog.csdn.net/ZX714311728/article/details/69628836

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值