centos6.5的tensorflow安装跳坑

来源:互联网 发布:逍遥模拟器没网络 编辑:程序博客网 时间:2024/06/11 08:03

1.首先安装python环境,其实对于任何一台linux机器都已经具备了python环境,但是如果想要事情变得简单的话,可以使用anaconda,anaconda下载地址https://repo.continuum.io/archive/;选择一个版本适中的安装,本人选择2.3.0。anaconda安装完成后,conda、pip等命令就可以用了。

2.安装tensorflow步骤

conda create -n tensorflow python=2.7
source activate tensorflow;
conda install -c conda-forge tensorflow;
source activate tensorflow;

3.出现的问题及跳坑方法

第一个:

import tensorflow as tfTraceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>    from tensorflow.python import *  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module>    from tensorflow.python import pywrap_tensorflow  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>    _pywrap_tensorflow = swig_import_helper()  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)ImportError: /lib64/libc.so.6: version `GLIBC_2.15' not found (required by /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

wget http://ftp.gnu.org/pub/gnu/glibc/glibc-2.20.tar.xz
xz -d glibc-2.20.tar.xz
tar -xvf glibc-2.20.tar
cd glibc-2.20
mkdir build
cd build
../configure –prefix=/usr –disable-profile –enable-add-ons –with-headers=/usr/include –with-binutils=/usr/bin
make && make install

第二个:

 import tensorflow as tfTraceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>    from tensorflow.python import *  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module>    from tensorflow.python import pywrap_tensorflow  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>    _pywrap_tensorflow = swig_import_helper()  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

使用“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

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/usr/lib/x86_64-linux-gnu
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
ln -s libstdc++.so.6.0.17 libstdc++.so.6

第三个:

import tensorflow as tfTraceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>    from tensorflow.python import *  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module>    from tensorflow.python import pywrap_tensorflow  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>    _pywrap_tensorflow = swig_import_helper()  File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)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://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

再次使用后成功安装,测试如下

>>> import tensorflow as tf>>> matrix1 = tf.constant([[3., 3.]])>>> matrix2 = tf.constant([[2.],[2.]])>>> product = tf.matmul(matrix1, matrix2)>>> print productTensor("MatMul:0", shape=(1, 1), dtype=float32)>>> sess = tf.Session()>>> result = sess.run(product)>>> print result[[ 12.]]>>> sess.close()>>> exit()

本博文后面内容转自http://blog.csdn.net/vfgbv/article/details/54018590

原创粉丝点击