折騰了一天安裝tensorflow環境,終於可以運行,也記錄一下安裝中容易犯的錯誤總結(寫給python小白們)
一、win7 雙系統 安裝ubuntu 16.04 ,參考 http://jingyan.baidu.com/article/60ccbceb18624464cab197ea.html
以下是容易遇到的問題:
1、iso要用64位系統
2、安裝過程中,聯想Thinkpad 按F1 進入Bois 可能需要修改 “F12 選擇啟動方式”的選項,確保該項為Enable
3、重啟 , F12 , 選擇USB HDD 啟動,進行ubuntu 的安裝
4、分區過程中, 如果window系統已經用了很多個主分區, ubuntu添加分區的時候 ,都選邏輯分區, 否則會遇到磁盤不可用的問題, 因為最多只能有4個主分區
二、ubuntu中安裝環境
1、更新源, 16.04的選用了aliyun的比較快
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
2、ubuntu su root
使用當前登錄賬號, sudo passwd root
設置密碼, 然后就可以 su root 了
3、安裝python pip
ubuntu16.04自帶python2.7.11+ 和 python 3.5.5, 不用自己編譯安裝, 默認 python是python2.7.11, python3是python3.5.5
直接apt-get install 無法安裝pip 提示缺少很多依賴包, 網上介紹了各種安裝pip方法, 使用 get-pip.py 安裝最方便, 參考 https://pip.pypa.io/en/stable/installing/
get-pip.py 官網下載地址: https://bootstrap.pypa.io/get-pip.py
執行 python get-pip.py 安裝pip (此時安裝的是python2.7的pip)
如果再使用 python3 get-pip.py 順手把pip3 也裝上的話 ,就會發現 pip 變成了 pip3 (可以用 pip -V 查看)
這時需要到 which pip , 到對應目錄/usr/local/bin/刪掉pip, ln -s pip2 pip , 將pip改回pip2的引用
4、安裝tensorflow
安裝github上的說明裝就可以(其他是前面幾部都做對了,尤其是pip)
安裝0.8 https://github.com/tensorflow/tensorflow/blob/r0.8/tensorflow/g3doc/get_started/os_setup.md
ubuntu下 :
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl
以前一直提示 “xx whl is not a supported wheel on this platform.” 錯誤, 主要是pip混亂導致的
至此大功告成~
$ 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