Cuda+cudnn+anaconda+python+tensorflow+pytorch的安装(ubuntu16.04)

通过在tesla和rtx2080ti型号的gpu安装配置环境,总结各个帖上的经验,也踩过一些坑,找到一个比较稳定的版本组合:

Cuda: 9.0

Cudnn:7.4.2

Python 3.5

Tensorflow
1.9.0

下面是各软件安装步骤:

I.cuda:首先下载cuda9.0的安装包,这里我是用的是ubuntu16.04版本,也比较稳定,下载链接:cuda链接

下载完成后打开所在路径,在命令行输入:

  1. sudo sh cuda_9.0.176_384.81_linux.run, 然后按照提示进行,依次选择accept, yes就行,(安装显卡驱动文件时有可能会提示有x文件,我们就可以不用安装显卡驱动,安装完cuda之后,可能需要重装显卡驱动)。

vim ~/.bashrc

添加环境变量:

在末尾添加:

export PATH=/usr/local/cuda-9.0/bin${
     PATH:+:${
     PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:${
     LD_LIBRARY_PATH:+:${
     LD_LIBRARY_PATH}}
  1. source ~/.bashrc生效

  2. cat /usr/local/cuda/version.txt查看是否安装成功,出现如图:

II.Cudnn,下载链接:cudnn链接

打开下载所在路径tar zxvf cudnn-10.0-linux-x64-v7.4.2.24.tgz

安装:

sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

查看cudnn版本:cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2,出现如图:

III.Anaconda:anaconda网址(网上的资源可能更新,需要去官网找)

打开所在路径,输入sh Anaconda3-2019.03-Linux-x86_64.sh -p (路径名) -u

修改配置文件:vim ~/.bashrc

在末尾添加:export PATH=“(路径名)/bin:$PATH”

source ~/.bashrc生效

IV.Python

创建python3.5环境:conda create -n py35 python=3.5 anaconda

vim ~/.bashrc,在末尾添加:

export PATH=“(路径名)/envs/py35/bin:$PATH

source ~/.bashrc 生效

python -V查看版本:

5.tensorflow&keras&pytorch:pip install tensorflow-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install keras
pip install torch torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple

关于默认pip镜像源的问题,可以参见pip镜像源

6.最后下载源永久改变的方法:

cp /etc/apt/sources.list /etc/apt/sources.list.bak
vim /etc/apt/sources.list

添加:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

更新:

apt-get update
apt-get upgrade

参考:https://www.linuxidc.com/Linux/2018-08/153709.htm

你可能感兴趣的:(linux环境配置,环境配置)