Ubuntu20.04安装Nvidia驱动+CUDA11.0+Pytorch+Opencv脚本

2021年1月29日 664点热度 0人点赞 0条评论

z注意

对于一个全新的Ubuntu20.04系统,我们将使用这个脚本安装GPU驱动、CUDA11.0、cudnn11.2、Python、Pytorch和Opencv。

注意,请首先手动下载cudnn11.2 地址:https://developer.nvidia.com/rdp/cudnn-download
注意,请首先手动下载cudnn11.2 地址:https://developer.nvidia.com/rdp/cudnn-download
注意,请首先手动下载cudnn11.2 地址:https://developer.nvidia.com/rdp/cudnn-download

Attention!Please download cudnn11.2 manually URL:https://developer.nvidia.com/rdp/cudnn-download
Attention!Please download cudnn11.2 manually URL:https://developer.nvidia.com/rdp/cudnn-download
Attention!Please download cudnn11.2 manually URL:https://developer.nvidia.com/rdp/cudnn-download

因为,使用cudnn必须接受nvidia的许可并同意nvidia的使用条款。如果只追求“一键安装”,那么很容易地把nvidia的cudnn上传到github或者googledrive,然后使用wget下载。但这可能是违反nvidia规定的。

Shell script

# CUDA installation
# Version==11.0

# Method 1

# Nvidia Driver installation
# sudo apt install nvidia-driver-450
# sudo reboot

# wget https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_450.51.06_linux.run
# sudo sh cuda_11.0.3_450.51.06_linux.run

# Method 2
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
sudo apt-get update
nvcc --version

# Download cuDNN from Nvidia: https://developer.nvidia.com/rdp/cudnn-download for version 10.1
echo "Please download cuDNN from https://developer.nvidia.com/rdp/cudnn-download"

tar -xzvf cudnn-11.2-linux-x64-v8.1.0.77.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 /usr/local/cuda/lib64/libcudnn*
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

# Add the following line to ~/.bashrc
echo "export PATH=PATH:/usr/local/cuda-11.0/bin" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/cuda-11.0/lib64"  >> ~/.bashrc
source ~/.bashrc

# Install Conda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sudo bash ./Miniconda3-latest-Linux-x86_64.sh
export ANACONDA_HOME=/usr/lib/miniconda3/
echo "export PATH=PATH:ANACONDA_HOME/bin" >> ~/.bashrc
source ~/.bashrc

# Install Pytorch
conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch

# Install Opencv
sudo apt update
sudo apt install libopencv-dev python3-opencv
pip install opencv-python

南国羽

I am a master student of computer science at Uppsala University in Sweden. Computer vision and machine learning are my research interests. I am looking for a Ph.D. position.

文章评论