建议用ubuntu18.04lts桌面版,因为自带的python3.6,ubuntu20.04是python3.8,而很多python模块还只支持python3.7甚至3.6。
现在物理机上装好ubuntu18.04,装完后开始操作(建议xshell远程,方便复制命令):
#设置root密码
sudo passwd root
#安装基本工具
sudo apt-get install -y ssh vim gcc unzip g++ make cmake python3-pip libzip-dev build-essential gfortran git pkg-config python-dev software-properties-common wget libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libopencv-dev libgflags-dev libgoogle-glog-dev liblmdb-dev libblas-dev libatlas-base-dev libopenblas-dev libgphoto2-dev libeigen3-dev libhdf5-dev python3-dev python3-pip python3-nose python3-numpy python3-scipy --no-install-recommends libboost-all-dev doxygen
#系统换源更新,这里是ubuntu18.04,如果是20.04记得自己换源
sudo rm -rf /etc/apt/sources.list && sudo vim /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
sudo apt-get clean && sudo apt-get update && sudo apt-get upgrade -y && sudo apt autoremove
#换pip3源
sudo mkdir ~/.pip && sudo vim ~/.pip/pip.conf
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
#卸载自带nVidia驱动(实际上并没有自带驱动)
sudo apt purge nvidia*
#禁用nouveau驱动
sudo vim /etc/modprobe.d/blacklist.conf
blacklist nouveau
options nouveau modeset=0
sudo update-initramfs -u
#重启并从ssh进去
sudo init 6
#查看nouveau驱动是否禁用
lsmod | grep nouveau
#关闭gdm3
sudo systemctl stop gdm3
#安装cuda(含显卡驱动),我安装的最新版本,各位可访问官网来查找最新版本号
wget https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.19.01_linux.run
sudo sh cuda_11.3.1_465.19.01_linux.run
accept
选择Install
#配置环境变量
sudo vim ~/.bashrc
export PATH=/usr/local/cuda-11.3/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.3/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source ~/.bashrc
#验证nVidia驱动
nvidia-smi
#验证cuda
nvcc -V
#安装cudnn,在官网下载
sudo tar zxvf cudnn-11.3-linux-x64-v8.2.1.32.tgz -C ./
sudo cp cuda/include/cudnn* /usr/local/cuda/include && sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn* /usr/local/cuda/lib64/libcudnn*
sudo dpkg -i libcudnn8_8.2.1.32-1+cuda11.3_amd64.deb
sudo dpkg -i libcudnn8-dev_8.2.1.32-1+cuda11.3_amd64.deb
sudo dpkg -i libcudnn8-samples_8.2.1.32-1+cuda11.3_amd64.deb
sudo init 6
#验证cudnn
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
出现Result = PASS成功
#安装pytorch
pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
#验证pytorch
python3
import torch
import torchvision
print(torch.cuda.is_available())
cdunn如果大家下载不了的话,可以私信我(我不一定及时回)或者自己通过其他途径去下载。
很多人到这可以告一段落了,接下来如果需要安装NVIDIA VIDEO CODEC SDK、OpenCV v3/v4、Boost、HDF5 、denseflow请先做好心理建设工作,然后查阅我的另一篇文章。