tensorflow在centos安裝

1.安裝python2.7

下載python-2.7.5.tar.gz文件,

tar -xzvf python-2.7.5.tar.gz

cd python-2.7.5

./configure --prefix=/usr/local/python2.7  --enable-unicode=ucs4

make && make install

建立軟連接,使系統默認的python指向python2.7

mv /usr/bin/python /usr/bin/python2.6.6.old

ln -s /usr/local/python2.7/bin/python   /usr/bin/python

已經安裝完成python的安裝或升級的全部操作了,我們再來看一下現在的python的版本:

# python -V

Python 2.7.5

雖然現在python已經安裝完成,但是使用yum命令會有問題——yum不能正常工作:

這是因爲yum默認使用的python版本是2.6.6,到哪是現在的python版本是2.7.5,故會出現上述問題,只需要該一下yum的默認python配置版本就行了:

#vi /usr/bin/yum

將文件頭部的#!/usr/bin/python改爲

#!/usr/bin/python2.6

2. 安裝setuptools

wget https://pypi.python.org/packages/source/s/setuptools/setuptools-3.3.tar.gz
tar zxvf setuptools-3.3.tar.gz
cd setuptools-3.3
python setup.py build
sudo python setup.py install

3.安裝pip

從pip官網 https://pypi.python.org/pypi/pip 下載pip的源代碼
#解壓
tar -zxvf pip-1.5.5.tar.gz 
cd pip-1.5.5
#安裝
sudo python setup.py install

4.安裝tensorflow

# 僅使用 CPU 的版本
pip install https://storage.googleapis.com/tensorflow/
linux(小寫)/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

如果numpy下載不下來,可以使用pip install numpy 安裝

# 開啓 GPU 支持的版本 (安裝該版本的前提是已經安裝了 CUDA sdk)
pip install https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl

5.測試:

運行 TensorFlow
打開一個 python 終端:
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>

6. 

遇到的問題及處理方法

Python 2.7.3 (default, Apr 26 2016, 11:18:30) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (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)

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



Python 2.7.3 (default, Apr 26 2016, 11:18:30) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (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)




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位)

下載新版本,地址: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
#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

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





>>> import tensorflow as tf
Traceback (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://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



終於成功了。
[root@pachong1 lib64]# python
Python 2.7.3 (default, Apr 26 2016, 11:18:30) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> matrix1 = tf.constant([[3., 3.]])
>>> matrix2 = tf.constant([[2.],[2.]])
>>> product = tf.matmul(matrix1, matrix2)
>>> print product
Tensor("MatMul:0", shape=(1, 1), dtype=float32)
>>> sess = tf.Session()
>>> result = sess.run(product)
>>> print result
[[ 12.]]
>>> sess.close()
>>> exit()









發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章