最近在學習google新開源的深度學習框架tensorflow。發現安裝它的時候,需要依賴python2.7.X;我之前一直使用的linux是centos。而centos不更新了,里面的自帶的python一般都是python2.6以下的。不僅如此,系統里面很多組件又依賴python2.6,所以導致你都不能替換掉它。無奈之下,選擇ubuntu了。下面介紹一下使用ubuntu安裝tensorflow遇到的一些問題。
1、ubuntu無法用Winscp連接
解決辦法:
(1)、采用橋接的方式進行上網(由於是用虛擬機安裝的操作系統)
(2)、利用ps -e |grep ssh 查看是否有sshd進程開啟。如果沒有則需要安裝openssh-server
安裝的方式:sudo apt-get install openssh-server
啟動相應的進程:/etc/init.d/ssh start
(3)、此時需要reboot系統
(4)、由於ubuntu最初root的用戶是沒有被激活的,所以需要通過修改root用戶密碼來激活root用戶。
完成即可連接了。
2、安裝tensorflow。
由於我的ubuntu是最新版的(ubuntu-16.04-desktop-amd64),里面自帶的python是2.7.11。因此滿足要求。由於tensorflow有三種安裝方式,這里采用的是pip安裝方式。下面開始安裝tensorflow:
(1)首先安裝pip
sudo apt-get install python-pip python-dev
(2)利用pip安裝tensorflow
sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl
安裝好了后,如下圖所示:
根據上面黃色的提示,叫我升級pip:於是我就按照他的要求升級了,執行:pip install --upgrade pip
3、檢驗tensorflow是否安裝成功
通過下面一段代碼來測試tensorflow是否安裝成功:
$ 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
>>>
下面是我執行的結果如下圖所示:

4、安裝python-numpy ,python-scipy,python-matplotlib
sudo apt-get install python-numpy
sudo apt-get install python-scipy
sudo apt-get install python-matplotlib
驗證是否安裝成功:(如下圖所示)