ubuntu16.04 +NVIDIA驱动+cuda8.0+cudnn+andaconda+tensorflow(GPU版)+Spyder+pycharm全套配置

ubuntu16.04 +NVIDIA驱动+cuda8.0+cudnn+andaconda+tensorflow(GPU版)+Spyder+pycharm全套配置

重装了ubuntu系统,由于是要进行深度学习相关的工作研究,所以先进行以下简单的配置:

环境: Ubuntu 16.04 64bit
Nvidia GeForce GTX 1080ti

首先安装好Ubuntu16.04,然后先安装一些依赖

sudo apt-get update

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

sudo apt-get install –no-install-recommends libboost-all-dev

sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

sudo apt-get install git cmake build-essential

一.NVIDIA显卡驱动安装

由于是重装的系统,不存在卸载原先驱动的问题
(需要卸载的问问题参考:http://www.linuxidc.com/Linux/2016-12/138907.htm
方法一:
首先介绍一下我的安装流程,我所采用的是PPA的安装方式:

sudo add-apt-repository ppa:graphics-drivers/ppa

sudo apt-get update

sudo apt-get install nvidia-378 nvidia-prime
接下来就可以进行测试,若出现问题,
参考原博:http://www.cnblogs.com/matthewli/p/6715553.html
方法二:
操作步骤如下:

屏蔽开源驱动nouveau

安装过程会询问是否屏蔽,手动屏蔽也有多种操作方式,如通过blacklist.conf或Grub2。这里选择blacklist:

创建新文件:

sudo vim /etc/modprobe.d/blacklist-nouveau.conf

内容为

blacklist nouveau

options nouveau modeset=0

再更新

sudo update-initramfs -u

结束X-window服务

安装Nvidia驱动需要结束x-window服务,据说这一步很重要。

KUbuntu : sudo /etc/init.d kdm stop

Ubuntu : sudo /etc/init.d gdm stop

Ubuntu(>11.10) : sudo /etc/init.d lightdm stop 或sudo service lightdm stop

我这里是lightdm,不确定是哪个可以都试试,或是直接 init 3

按Ctrl + Alt + F1 进入tty1控制台

安装驱动

执行驱动安装的run文件

sudo sh ./NVIDIA-Linux-x86_64-367.57.run 或sudo sh ./NVIDIA*.run

(如果安装不正常则带 –uninstall 参数卸载)

安装完后重启X-window

KUbuntu : sudo /etc/init.d kdm restart

Ubuntu : sudo /etc/init.d gdm restart

Ubuntu(>11.10) : sudo start lightdm 或 sudo service lightdm start

按Ctrl + Alt + F7返回tty7图形界面

检查

nvidia-smi 可显示显卡一些信息

nvidia-settings 显卡设置

可能出现的问题:输入sudo vim /etc/modprobe.d/blacklist-nouveau.conf命令时,会输出: sudo: vim: 找不到命令 的问题

解决办法:

1.在命令行敲入“vi”后按”tab”键,可以看到目前系统中只安装了vi和vim.tiny。

vim是从VI发展而来的一个文本编辑器,功能更强大。而vim.tiny是vim的精简版,所以,安装vim势在必行。

2.输入命令:sudo apt-get install vim-gtk
若输出:软件包 vim-gtk 没有可安装候选 ,则(连网前提下)

步骤一:在终端输入命令:sudo apt-get update && sudo apt-get upgrade

解释:update == 更新软件包列表 upgrade == 升级系统中的所有软件包

步骤二:在线安装vim,在终端输入命令:sudo apt-get install vim-gtk

即可

二.安装cuda8

首先也是去下载cuda toolkit 8.0(https://developer.nvidia.com/cuda-downloads),可以自己注册一个账号。

一定要选择runfile.下载完成之后,执行sudo sh cuda_8.0.44_linux.run –override

然后就进入安装过程,开始都是End User License Agreement,你可以CTRL +C 跳过,然后accept,下面就是安装的交互界面,开始的Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?选择n,因为你已经安装驱动了。
Using more to view the EULA.

End User License Agreement

Preface

The following contains specific license terms and conditions
for four separate NVIDIA products. By accepting this
agreement, you agree to comply with all the terms and
conditions applicable to the specific product(s) included
herein.

NVIDIA CUDA Toolkit

Description

The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references. The NVIDIA CUDA Toolkit
License Agreement is available in Chapter 1.

Default Install Location of CUDA Toolkit

Windows platform:

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?
(y)es/(n)o/(q)uit: n

Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
[ default is /home/kinny ]:

Installing the CUDA Toolkit in /usr/local/cuda-8.0 …
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/kinny …
Copying samples to /home/kinny/NVIDIA_CUDA-8.0_Samples now…
Finished copying samples.

===========

= Summary =

Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /home/kinny, but missing recommended libraries

Please make sure that
- PATH includes /usr/local/cuda-8.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing with the name of this run file:
sudo .run -silent -driver

Logfile is /tmp/cuda_install_17494.log
还需要设置环境变量,输入命令:

sudo gedit ~/.bashrc

然后如果是32位的Linux系统在打开文件的末尾添加:

export PATH=/usr/local/cuda/bin:$PATH

export LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH

如果是64位的Linux系统则在打开文件的末尾添加:

export PATH=/usr/local/cuda/bin:$PATH

export LD_LIBRARY_PATH=/usr/local/cuda/64:$LD_LIBRARY_PATH

保存文件并关闭,最后更新一下:

source ~/.bashrc

重启之后测试CUDA的sammples

cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery

sudo make

./deviceQuery

如果看到一些GPU的信息说明安装成功

三.配置cuDNN
(参照http://blog.csdn.net/t5131828/article/details/53258925

cuDNN是GPU加速计算深层神经网络的库。

(a)首先去官网(https://developer.nvidia.com/rdp/cudnn-download)下载cuDNN,需要注册一个账号才能下载
我已经下载好了,直接分享吧http://pan.baidu.com/s/1bp3hTmv
Cuda8.0支持Cudnn v5.0和v5.1,但是在安装tensorflow之后测试其示例代码mnist时,提示该代码基于Cudnn v5.1生成,因此我又改成了v5.1。

(b)下载cuDNN5.1之后进行解压,cd进入cuDNN5.1解压之后的include目录,在命令行进行如下操作:
sudo cp cudnn.h /usr/local/cuda/include/ #复制头文件

(c)再将cd进入lib64目录下的动态文件进行复制和链接:

sudo cp lib* /usr/local/cuda/lib64/ #复制动态链接库
cd /usr/local/cuda/lib64/sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件
sudo ln -s libcudnn.so.5.1.5 libcudnn.so.5 #生成软衔接
sudo ln -s libcudnn.so.5 libcudnn.so #生成软链接

四.安装anaconda

(a)网址:https://www.continuum.io/downloads,选择PYTHON2.7版本,根据自己系统位数,然后下载
下载完之后执行下载的文件,比如:

bash Anaconda2-4.2.0-Linux-x86_64.sh

后面就根据提示执行就可以了,很简单

(b1)你在命令行输入python,会调用系统自带的python,所以执行完之后需要替换python(或用b2)

vim ~/.bashrc

加入anaconda的安装目录是/home/xxx/anaconda2,那么在文件的最后加上

alias python=’/home/xxx/anaconda2/bin/python‘

然后source .bashrc。重启终端完成配置

你再执行python就变成了anaconda的python
(b2) 最后会询问是否把anaconda的bin添加到用户的环境变量中,选yes(y)

然后输入source ~/.bashrc

再输入python,则就变成了anaconda的python

之后记得重启

五.基于anaconda下安装TensorFlow

首先,创建一个conda环境。命名为TensorFlow
终端输入:conda create -n tensorflow python=2.7
(-n意为-name, 根据python安装的版本不同后面数字进行修改)
然后激活该环境,并在该环境下安装TensorFlow
source activate tensorflow

其次,我们用pip安装带有gpu版本的TensorFlow,
下载地址为:清华软件源 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
将所需要的版本的TensorFlow版本下载到目录下,设该目录为TF_PYTHON_URL
则在终端输入:pip install –ignore-installed –upgrade TF_PYTHON_URL
如此,完成GPU版的TensorFlow的安装。使用完毕后,需关闭tensorflow环境
source deactivate 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))

可能出现的问题:
当我们用anaconda自带的IDE Spyder编辑python时,显示无法导入tensorflow模块,
这时候的解决方法参考该文章:http://blog.csdn.net/u010899985/article/details/59482825

六、pycharm的安装
参考该文章:http://blog.csdn.net/sinat_23137713/article/details/53018104




猜你喜欢

转载自blog.csdn.net/qq_17130909/article/details/78388696