linux安装tensorflow

声明:本文是根据网上几篇文章整理而成,并经实际安装验证可用。主要是为笔记记录,无商业目的,在此感谢参考的网文。


1. 安装python2.7.9

2. 下载pip8.1.2  https://pypi.python.org/pypi/pip

tar zvxf pip-8.1.2.tar.gz

cd pip-8.1.2

python setup.py install

如果出现ImportError:cannot import name HTTPSHandler的错误,原因在于openssl,openssl-devel两个文件包未正确安装:

yum install openssl

yum install openssl-devel

安装完成后,重新编译安装python

cd Python-2.7.9

./configure

make install

3. 安装tensorflow

pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

如果出现ImportError:/lib64/libc.so.6: version `GLIBC_2.15' not found 的错误,

#strings /lib64/libc.so.6|grep GLIBC

可能发现tensorflow0.80版本编译的时候使用GLIBC_2.15,系统自带的是GLIBC_2.12,所以报错了。依次如下修复:

yum install gcc
wget http://ftp.gnu.org/pub/gnu/glibc/glibc-2.17.tar.xz
xz -d glibc-2.17.tar.xz
tar -xvf glibc-2.17.tar
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

 重新加载tensorflow,发现

ImportError:/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found

#strings /usr/lib64/libstdc++.so.6 | 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

没有GLIBCXX_3.4.14版本支持,继续安装(注意:libstdc++6_4.7.2-5_amd64.deb这是64位,libstdc++6_4.7.2-5_i386.deb这个是32位)

下载新版本,地址:

wget http://ftp.de.debian.org/debian/pool/main/g/gcc-4.7/libstdc++6_4.7.2-5_amd64.deb
ar -x libstdc++6_4.7.2-5_amd64.deb&&tar xvf data.tar.gz  
#cd /root/Downloads/glibc-2.17/build/usr/lib/x86_64-linux-gnu/
#ll
lrwxrwxrwx 1 root root     19 Apr 26 15:21 libstdc++.so.6-> libstdc++.so.6.0.17
-rw-r--r-- 1 root root 991600 Jan  7  2013 libstdc++.so.6.0.17

/

usr/lib64/libstdc++.so.6
/root/Downloads/glibc-2.17/build/usr/lib/x86_64-linux-gnu/libstdc++.so.6

#mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
#cp libstdc++.so.6.0.17 /usr/lib64/
#cd /usr/lib64/

#chmod +x libstdc++.so.6.0.17
#ll libstdc++.so.6.0.17
-rwxr-xr-x 1 root root 991600 Apr 26 15:30 libstdc++.so.6.0.17
#ln -s libstdc++.so.6.0.17 libstdc++.so.6

#strings /usr/lib64/libstdc++.so.6 | 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_DEBUG_MESSAGE_LENGTH

重新加载tensorflow,发现

ImportError: /usr/lib64/libstdc++.so.6:version `GLIBCXX_3.4.19' not found (required by/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

从网上下载libstdc++.so.6.0.20 
http://ftp.de.debian.org/debian/pool/main/g/gcc-4.8/
或者
http://download.csdn.net/detail/pomelover/7524227

放到/usr/lib64/下
#chmod +x libstdc++.so.6.0.20
#rm libstdc++.so.6
#ln -s libstdc++.so.6.0.20 libstdc++.so.6
#strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX

[root@pachong1 lib64]# strings /usr/lib64/libstdc++.so.6 | 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_3.4.20
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

 


重新加载tensorflow,发现

ImportError: No module namedprotobuf

 

执行

pip install --upgradeprotobuf==3.0.0b2

 

重新加载tensorflow,发现

ImportError: cannot import namepywrap_tensorflow

解决办法:

From the path in your stack trace (/git/tensorflow/tensorflow/…), it lookslike your Python path may be loading the tensorflow libraries from the sourcedirectory, rather than the version that you have installed. As a result, it isunable to find the(compiled) pywrap_tensorflow library, which isinstalled in a different directory.

A common solution isto cd out of the /git/tensorflow directory before starting python or ipython.

也就是说,可以cd到其他目录,再执行python,加载tensorflow就可以


你可能感兴趣的:(linux安装tensorflow)