[How to install multiple versions of CUDA, cudnn, pytorch, torchvision, torchaudio in the anaconda virtual environment and teach the environment configuration step by step]
If you need to use different versions of cuda, you only need to create different virtual environments and download the required versions of cuda and cudnn.
0, operation code summary
Take cuda11.3, cudnn8.2.1 as an example
View/update driver caps
Create an environment:
conda create -n cuda11_3_cudnn8_2_1_env python=3.8
Activate the environment:
conda activate cuda11_3_cudnn8_2_1_env
Query the cuda version:
conda search cudatoolkit --info
Query the cudnn version:
conda search cudnn --info
Install cuda:
conda install cudatoolkit=11.3
Install cudnn:
conda install cudnn=8.2.1
Install pytorch, torchvision, torchaudio:
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
verify:
conda list
python
import torch
torch.cuda.is_available()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
return true for success
Specific operations:
1. View/update the nvidia driver version number
Update the driver first, then check the version. You can also check directly without updating.
GeForce Experience can be updated to the latest version of the driver
. Check the control panel to view the current highest supported cuda version.
I support up to 11.7.99 here.
2. Create a virtual environment
Enter Anaconda Promot as administrator
conda create -n cuda11_3_cudnn8_2_1_env python=3.8
- 1
activation environment
conda activate cuda11_3_cudnn8_2_1_env
- 1
3. Check the version of cuda (cudatoolkit) and cudnn
Check the cuda version supported by conda and select the appropriate version
conda search cudatoolkit --info
- 1
You can see that the latest support is 11.3.1, and cuda must be >= 11.3. I am 11.7, which is satisfied.
Check the cudnn version supported by conda and select the appropriate version
conda search cudnn --info
- 1
You can see that the latest support is up to 8.2.1, which requires cudatoolkit to be between 11.0 and 11.4. I am 11.3, which is satisfied.
4. Install cuda (cudatoolkit) and cudnn
conda install cudatoolkit=11.3
- 1
conda install cudnn=8.2.1
- 1
5. Install pytorch , torchvision, torchaudio
Go to https://pytorch.org/get-started/locally/
to select the corresponding version and copy the official code
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
- 1
6. Verify that the installation was successful
conda list
- 1
Check whether the corresponding version has been downloaded
Code verification, enter the python code mode
python
- 1
import torch
- 1
No exception was returned, indicating that pytorch is installed
torch.cuda.is_available()
- 1
Returns true, indicating that cuda is also installed