在redhat 6.5上安装tensorflow
操作系统为redhat 6.5操作系统64位,自带python为2.6版本,已不支持tensorflow,需升级为python2.7
[root@bogon opt]# python -V
Python 2.6.6
一、python升级
1、下载解压配置
[root@bogon opt]#wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
[root@bogon opt]# tar zxvf Python-2.7.10.tgz
[root@bogon opt]# cd Python-2.7.10
[root@bogon opt]#./configure --enable-shared --prefix=/usr/local/python27
2、配置zlib与ssl
a、确认安装zlib,zlib-dev,没有安装使用yum安装,修改./Modules/Setup文件
[root@bogon Python-2.7.10]# vi ./Modules/Setup# 找到下边这一行内容,去掉注释
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
b、确认安装openssl,openssl-dev,修改./Modules/Setup文件
# 找到下边这一行内容,去掉注释
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
3、编译安装
[root@bogon opt]# make
[root@bogon opt]# make install
4、 查看 python 版本信息
[root@bogon Python-2.7.10]# python -V
Python 2.6.6
# 版本依旧是 2.6.6
5、 用 python2.7 替换旧版本
[root@bogon Python-2.7.10]# cd /usr/bin/
[root@bogon bin]# ls python* -l # 旧 python 版本信息
-rwxr-xr-x. 2 root root 4864 2月 22 2013 python
lrwxrwxrwx. 1 root root 6 10月 22 18:38 python2 -> python
-rwxr-xr-x. 2 root root 4864 2月 22 2013 python2.6
[root@bogon bin]# rm /usr/bin/python
[root@bogon bin]# ln -s /usr/local/python27/bin/python2.7 /usr/bin/python
[root@bogon bin]# ls python* -l
lrwxrwxrwx. 1 root root 33 10月 23 00:01 python -> /usr/local/python27/bin/python2.7
lrwxrwxrwx. 1 root root 6 10月 22 18:38 python2 -> python
-rwxr-xr-x. 2 root root 4864 2月 22 2013 python2.6
6、 重新验证 Python 版本信息
[root@bogon bin]# python -V
Python 2.7.10
可以看到,系统识别的 python 版本已经是 python 2.7.10
执行 python -V 遇到的问题:
python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
# 原因:linux系统默认没有把/usr/local/python27/lib路径加入动态库搜索路径
解决:
[root@vip ~]# vim /etc/ld.so.conf
# 添加如下一行内容
/usr/local/python27/lib
[root@bogon ~]# ldconfig # 使新添加的路径生效
二、解决 yum 兼容性问题
因为 yum 是不兼容 Python 2.7 的,所以 yum 不能正常工作,我们需要指定 yum 的 Python 为 2.6。
1. 升级 python 后 yum 出现的问题
[root@bogon bin]# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
... ... ... ...
2. 编辑 yum 配置文件
[root@vip bin]# vim /usr/bin/yum
#!/usr/bin/python
# 第一行修改为 python2.6.6
#!/usr/bin/python2.6
3. 验证 yum 问题解决
[root@bogon bin]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
三、安装python-pip
[root@bogon opt]#wget https://bootstrap.pypa.io/get-pip.py
[root@bogon opt]# python get-pip.py
Collecting pip
Using cached pip-9.0.1-py2.py3-none-any.whl
Collecting setuptools
Using cached setuptools-36.0.1-py2.py3-none-any.whl
Collecting wheel
Using cached wheel-0.29.0-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-36.0.1 wheel-0.29.0
四、安装
安装tensorflow
安装基于linux和python2.7的tensorflow 0.9
[root@bogon opt]# pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
Collecting tensorflow==0.9.0 from https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
Using cached https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
Requirement already satisfied: wheel in /usr/local/python27/lib/python2.7/site-packages (from tensorflow==0.9.0)
Collecting protobuf==3.0.0b2 (from tensorflow==0.9.0)
Using cached protobuf-3.0.0b2-py2.py3-none-any.whl
Collecting numpy>=1.8.2 (from tensorflow==0.9.0)
Downloading numpy-1.13.0-cp27-cp27m-manylinux1_x86_64.whl (16.6MB)
100% |████████████████████████████████| 16.6MB 81kB/s
Collecting six>=1.10.0 (from tensorflow==0.9.0)
Downloading six-1.10.0-py2.py3-none-any.whl
Requirement already satisfied: setuptools in /usr/local/python27/lib/python2.7/site-packages (from protobuf==3.0.0b2->tensorflow==0.9.0)
Installing collected packages: six, protobuf, numpy, tensorflow
Successfully installed numpy-1.13.0 protobuf-3.0.0b2 six-1.10.0 tensorflow-0.9.0
五、测试,文件添加一些内容,保存为test.py
import tensorflow as tf
hello = tf.constant('Hello,TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))
执行python -test.py报错,GLIBC_2.14 no FOND,查看libc.so.6
[root@bogon opt]# 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_PRIVATE
六、升级glibc为2.17
[root@bogon opt]# wget http://ftp.gnu.org/gnu/glibc/glibc-2.17.tar.gz
[root@bogon opt]#tar zxvf glibc-2.17.tar.gz
[root@bogon opt]# mkdir glibc-2.17-build
[root@bogon opt]# cd glibc-2.17-build/
[root@bogon opt]# ../glibc-2.17/configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
[root@bogon opt]# make
[root@bogon opt]# make install
[root@bogon opt]# strings /lib64/libc.so.6 |grep GLIBC_
[root@bogon opt]# 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
升级成功,执行python -test.py报错,GLIBCXX_3.4.14 no FOND,查看
[root@bogon lib64]# strings /usr/lib64/libstdc++.so.6.0.18 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH
七、升级gcc到4.8.2
参考http://blog.csdn.net/origin_lee/article/details/43231397
编译大约50分钟
[root@bogon lib64]# strings /usr/local/lib64/libstdc++.so.6.0.18 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH
升级成功
八、执行python test.py成功
[root@bogon opt]# python test.py
Hello,TensorFlow!
42
浙公网安备 33010602011771号