Create anaconda virtual environment in ubuntu environment and install pytorch-gpu version
1. Ubuntu environment
unbuntu:20.04
cuda:12.0
2. Install version
cuda:11.3
cudnn:8.2.0
python:3.8
pytorch:1.10.0
1. Find the corresponding version
- version connection lookup
2. Installation environment steps
2.1 download cuda
- Official website link: https://developer.nvidia.com/cuda-toolkit-archive
ubuntu
cuda
The highest matching environment version12.0
, I download11.3.0
- install command
wget https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda_11.3.0_465.19.01_linux.run sudo sh cuda_11.3.0_465.19.01_linux.run
选continue
填accept
电脑里有驱动,按空格取消【键盘最长的那个空白键】,把x去掉,选择install,安装
安装成功
- Configure environment variables
- Open the configuration file, [I need to use administrative rights, otherwise the file cannot be modified, added in front
sudo
]sudo vi /etc/profile
- Add configuration information [
cuda-11.3,11.3
It is the version I downloadedcuda
, please modify the number if the version is different]- Insertion method:
linux
modify the file command, press the key oncei
[i
representsinsert
insert], press the up, down, left, and right keys to modify the position of the mouse, and add data at the corresponding position - Save method: Click the upper left corner of the keyboard
Esc
, press and holdshift+:
, and enterwq!
Enter
export PATH=//usr/local/cuda-11.3/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-11.3/lib64$LD_LIBRARY_PATH
- Insertion method:
source
configuration filesource /etc/profile
- Open the configuration file, [I need to use administrative rights, otherwise the file cannot be modified, added in front
- Check if the installation is successful
- Enter
local
the path to viewcuda
the file namecd /usr/local ls -a
- Enter the relevant command [
cuda-11.3
modify according to your own file name]cd /usr/local/cuda-11.3/samples/1_Utilities/deviceQuery sudo make ./deviceQuery
- The result
Result=pass
was successful
- Enter
2.2 install cudnn
- Official website link: https://developer.nvidia.com/rdp/cudnn-archive
cuda
The version is11.3.0
, choosecudnn
:8.2.0
, but I don’t seecuda为11.3.0
the correspondingcudnn
specific version
- Unzip and copy to the corresponding folder
- Unzip [Find the downloaded file directory to unzip]
tar -xvf cudnn-11.3-linux-x64-v8.2.0.53.tgz
- Copy the file [the name of the decompressed file
cuda
]cd cuda sudo cp lib64/* /usr/local/cuda-11.3/lib64/ sudo cp include/* /usr/local/cuda-11.3/include/ sudo chmod a+r /usr/local/cuda-11.3/lib64/* sudo chmod a+r /usr/local/cuda-11.3/include/*
- view
cuDNN
versioncat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
- Check whether ordinary users
nvcc
can use [I don’t know if it is an ordinary user, and the sudo command is not used]
2.3 Steps to install pytorch
-
Create a virtual environment
conda create --name env_torch_cuda113 python=3.8
-
Enter the virtual environment
conda activate env_torch_cuda113
-
Install
pytorch
conda
Can't install it, it seems that it canconda
be changed topip
pip install torch==1.10.0+cu113 torchvision==0.11.0+cu113 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html
-
Whether the verification is successful
torch.__version__
-
Check
GPU
availabilitytorch.cuda.is_available()
2.4 The virtual environment created by importing pycharm
- Find
anaconda
the virtual environment directorypython
interpreter- my environment is in
aoaconda/dataapp/envs/env_torch_cuda113/bin/python.exe
- my environment is in
- Test the code again
import torch print(torch.__version__) print(torch.cuda.is_available()) print(torch.cuda.device_count()) print(torch.cuda.current_device())
The installation is complete! ! !
Summarize
ubuntu20.04
It doesn't seem to be necessarycuda,cudnn
, but I downloaded it- When installing , the relevant version requires only the installation command on
pytorch
the official website , but it can’t be installed. I found a command and changed my version number to install it. I haven’t found any problems yet.conda
pip
- Report an error later, talk about it later if there is a problem
- end