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”这个选项即可。到此为
止,深度学习环境和开发工具配置完成。