紧接着前几天的事:html
以后,决定买一台整机玩玩。python
而如今,主机终于回!来!了!主机回来干什么,固然是——配置环境。linux
老潘以前也有一些配置环境的文章,能够参考:ubuntu
-_-|| 没想到那会写了这么多配置环境的文章,可能那会遇到的问题比较多吧...配环境什么的,其实只要严格按照步骤来一步一步配,基本上不会出现什么问题,出现问题通常都是咱们某一步没有走对,而退回去再走比较麻烦而已。vim
而如今对于配环境来讲能够是轻车熟路了(前几年不知道踩了多少坑,到如今都印象深入),严格按照步骤来,安装Ubuntu和配置深度学习环境,1个小时多就搞定了。bash
接下来略微详细地讲一下过程。服务器
先放一组图吧。ssh
晚上开机还挺炫的,但其实对于老潘来讲炫不炫不重要,性能好就行...ionic
主机回来店家只给我装了Windows系统,对于老潘来讲,打游戏是次要的(哈哈哈哈...),忍住了先下载一个鬼泣5
玩玩的想法。先从Ubuntu官方下载了官方的镜像包。性能
官方最新的Ubuntu是20.10
,但对于搞事的人来讲,仍是18.04版本好一些(以前实验室用的是16.04)。
开始配置双系统,双系统是必须的,Ubuntu能够搞深度学习,也能够当服务器使,Windows则能够应付一些游戏和其余应急应用。
关于如何将下载好的Ubuntu系统镜像制做成U盘、如何安装,老潘这里不赘述了。能够看如下这篇文章,介绍的很详细,我就是按照这个严格来执行的:
固然若是有问题欢迎交流,直接留言便可~
虽然不赘述了,但仍是简单过一下:
进入BIOS,选择Ubuntu启动U盘,而后开始安装Ubuntu:
其余一路点点点,而后简单分个区。
而后开始安装...
等待半小时,装好了!
为何要设置ssh
,固然是想让这个Ubuntu充当一个服务器的做用,开启以后可使用ssh登陆去操做。
例如我,能够先把服务器开了,而后使用其余电脑,例如MAC,使用局域网经过SSH链接这个服务器便可。
怎么开启ssh呢?新的Ubuntu系统尚未安装SSH。
执行如下命令:
sudo apt install openssh-server sudo systemctl start ssh.service
而后能够经过netstat -lnp | grep 22
查看下开启没。
若是想要每次启动自动开启SSH,能够这样:
sudo systemctl enable ssh
这样就差很少啦。
默认Ubuntu安装的是llvmpipe这个显卡驱动,这个是linux下的公用显卡驱动,如今须要换成NVIDIA的。
首先禁用nouveau。
执行sudo gedit /etc/modprobe.d/blacklist.conf
加上如下这两句:
blacklist nouveau options nouveau modest=0
保存后,而后执行:
sudo updata-initramfs -u sudo reboot
重启后,Ctrl+Alt+F1
切换到tty界面,关闭lightdm(若是没有则不用管):
sudo service lightdm stop
而后更新一下apt源以及看一下系统推荐的NVIDIA驱动版本:
sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt-get update ubuntu-drivers devices
根据推荐的驱动版本,安装NVIDIA驱动:
sudo apt-get install nvidia-driver-460
若是嫌慢,能够添加阿里或者清华源:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bcakup sudo gedit /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-backports main restricted universe multiverse ##測試版源 deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed 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-backports main restricted universe multiverse ##測試版源 deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse # 清华大学源 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse ##測試版源 deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse # 源碼 deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse ##測試版源 deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
别忘了添加以后,进行更新二连:
sudo apt-get update sudo apt-get upgrade
这样就能够顺利的安装NVIDIA驱动了。
而后下载好如下三个深度学习伴侣:
开始安装吧!
Cuda固然是必需要装的。
找到下载好的11.1
cuda环境包(如今出来11.2了),而后执行:
sudo sh cuda_11.1.0_455.23.05_linux.run
会出来一堆blabla的选项:
对于老潘来讲,上一步中已经安装了cuda驱动,不须要再装旧版的(新版驱动兼容旧版驱动匹配的cuda),因此这里就把驱动选项去掉,其余的安装按照个人需求循序渐进来就好。
注意
若是你没有root权限,没法使用sudo
,想要安装cuda也是能够的。只要自定义好安装位置便可,运行以下命令便可将cuda安装到当前home下的software文件夹内:
./cuda_11.1.0_455.23.05_linux.run --silent --toolkit --toolkitpath=$HOME/software/cuda --defaultroot=$HOME/software/cuda
不论咋样安装好以后会显示:
按照上面的要求配置环境变量便可:
(base) oldpan@oldpan-fun:~/software$ vim ~/.bashrc 将 export PATH=/usr/local/cuda-11.1/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64:$LD_LIBRARY_PATH 添加到打开的文件中 (base) oldpan@oldpan-fun:~/software$ source ~/.bashrc (base) oldpan@oldpan-fun:~/software$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2020 NVIDIA Corporation Built on Tue_Sep_15_19:10:02_PDT_2020 Cuda compilation tools, release 11.1, V11.1.74 Build cuda_11.1.TC455_06.29069683_0
cudnn的安装就比较简单了,解决压缩包而后复制粘贴就行:
tar -xzvf cudnn-11.2-linux-x64-v8.1.1.33.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
安装Anaconda也很简单,从这里下载好(不想下的看老潘整理文末的软件包):
而后sh Anaconda3-2020.11-Linux-x86_64.sh
就行。
安装好以后,配置conda以及pip清华源,参考如下文字便可:
安装Pytorch就比较简单了,若是不想本身编译,直接从官方按照你的Cuda版本和Cudnn版本安装便可:
https://download.pytorch.org/whl/torch_stable.html
安装好Pytorch以后,测试一下cuda是否工做正常:
>>> import torch >>> torch.cuda.is_available() True >>> torch.ones(1).cuda() tensor([1.], device='cuda:0') >>> torch.cudnn_is_acceptable(torch.ones(1).cuda()) True
OK~
TensorRT单独发一篇文章来讲吧~
配环境须要不少软件包,例如:
有些能够在清华大学开源软件镜像站下载,可是TensorRT和CUDA、CUDNN须要从官方下并且须要注册并且很慢。
老潘整理了一些已经下载好的软件包。
公众号内回复015
获取,能够看看有没有你须要的:
想写的还有不少,下篇再讲(呼呼)。
若是有问题欢迎留言,欢迎关注「oldpan博客」公众号,老潘的所有家当都在这里了。很愿意与你交朋友~
http://www.javashuo.com/article/p-zgooujzy-kg.html
https://blog.csdn.net/ZPeng_CSDN/article/details/96726436
想知道老潘是如何学习踩坑的,想与我交流问题~请关注公众号「oldpan博客」。
老潘也会整理一些本身的私藏,但愿能帮助到你们,点击神秘传送门获取。