Ubuntu16.04搭建深度學習環境
1.安裝Python
step1:python官網去下載python解釋器
由於我的系統是64位,所有下載64位的python源碼Python-3.6.4.tar.xz
step2:利用命令tar-Jxvf Python-3.6.4.tar.xz -C destinationDir 解壓destinationDir是你想要解壓的地方。注意:tar.xz的解壓參數是-Jxvf , tar.gz的解壓參數-xzvf
step3:爲了能夠使用import matplotlib.pyplot as plt 時不出現下面這個錯誤
先更新ubuntu的軟件源,再安裝python3-tk,具體命令如下:
1備份原來的軟件源:sudo cp /ect/apt/sources.list /etc/apt/sources.list.bak
2跟換源:sudo gedit /etc/apt/sources.list ,然後將阿里雲的源換到裏面保存
3更新:sudo apt-get update
4更新軟件:sudo apt-get upgrade
阿里雲源:
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
安裝python3-tk,【python3-tk由tcl和tk兩個部分組成】,到網站https://www.tcl.tk/software/tcltk/download.html下載對應的tcl和tk,我下載的是8.6.8版本:
下載完成後解壓。
安裝tcl:
cdtcl8.6.8/unix
sudo./configure
sudomake
sudomake install
安裝tk:
cdtk8.6.8/unix
sudo./confiugre
sudomake
sudomake install
如果在安裝tk的過程中出現fatal error:X11/Xlib.h:No such file or directroy錯誤,是因爲x11沒有完整安裝,
使用如下命令安裝即可
sudo apt-get install libghc-x11-dev
說明:如果之前已經安裝過python,則需要重新按下面的安裝python的辦法安裝python,這裏的源碼安裝和以前安裝的源碼是一樣的。重新安裝python3.6後,進入python3.6命令交互模式,如果能夠出現
下面這個截圖,則說明安裝成功
在安裝python之前需要安裝zlib等包,具體命令如下:
sudo apt-get install zlib*
sudo apt-get install openssl
sudo apt-get install libssl-dev
sudo apt-get install libbz2-dev #後來使用pytorch時用到了
安裝python:
sudo ./configure –with-ssl=openssl --enable-shared
sudo make
sudo make install
sudo libpython3.6m.so.1.0 /usr/lib
執行第一條命令時一定要帶上—with-ssl參數,否則安裝完後不能使用pip3來安裝python的包,
在./configure過程中,默認是不能使用ssl功能的,pip3安裝python模塊要使用ssl功能,所以需要明
確指定;在安裝的過程中,他會自動更新pip3到9.0.1版本,所以不需要手動更新。
--enable-shared 解決後期安裝caffe,共享庫libpython3.6m.so.1.0問題,後期遇到重新編譯會很麻煩
補充手動安裝
pip命令如下:
sudoapt-get install python3-pip
sudopython3.6 -m pip3 install –upgrade pip [這兩條命令未測試,可以參考]
2.安裝Python機器學習常用模塊
step4:安裝numpy
sudo pip3 install numpy
step5:安裝matplotlib
sudo pip3 install matplotlib
step6:安裝scikit-learn
sudo pip3 install scikit-learn
step7:安裝scipy
sudo pip3 install scipy
step8:安裝pandas [用數據探索和數據分析]
sudo pip3 install pandas
step9:安裝statsmodels [主要用於統計分析]
sudo pip3 install statsmodels
step10:安裝gensim[用於文本挖掘]
sudo pip3 install gensim
step11:安裝tensorflow
sudo pip3 install tensorflow
step12:安裝keras
sudo pip3 install keras
step13:安裝jieba[用於分詞]
sudo pip3 install jieba
step14:安裝scikit-image
sudo pip3 install -U scikit-image
step15:安裝pillow
sudo pip3 install pillow
說明:matplotlib,scipy.misc,scikit-image,pillow都有imread,都可以讀取圖片,此5張圖參考其他的博客寫的
3.安裝PythonIDE
Python的IDE非常多,但是感覺看到eclipse非常親切,而且功能也很強大。
step14:下載JAVA安裝環境,解壓到相應的位置
tar-xzvf jdk-8u162-linux-x64.tar.gz -C destinationDir
step15:配置環境變量
sudovim /etc/profile
具體內容如下:
step15:下載eclipse,同樣解壓,配置環境變量如上圖
step16:安裝pydev,這裏選擇在線安裝方式。
啓動eclipse,help→installnew software
點擊add按鈕,並按照下圖填寫Repository
點擊OK,選中PyDev和PyDevMylyn Integration(optional),然後點擊下一finally
在安裝過程中會彈出提示,看提示,選擇允許即可,重啓eclipse,然後就可以創建Python項目
4.PyDevfor eclipse相關設置和使用
step17:啓動eclipse,window→preference→ Interpreters,設置python解釋器:點擊AdvancedAuto-Config,它會顯示
ubuntu中所有可以python解釋器,選擇合適的即可
step18:創建項目,選擇DevProject即可
輸入項目名稱,選擇“Create‘src’ folder and add it to thePYTHONPATH”這個選項即可。到此爲
止,深度學習環境和開發工具配置完成。