Anaconda installs pytorch-gpu (no need to change the source)

How to install the gpu version of pytorch in anaconda?

Note: I read a lot of posts and followed many methods to install. Finally, I found that when I enter print(torch.cuda.is_available()), it always returns false. The reason may be that many people download pytorch from the official website very slowly. Then choose to change the source, and then install it in conda mode. There is likely to be cuda that does not correspond to pytorch in other sources, and anconda was recently downloaded by default.

1. Open anaconda prompt input

conda create -n pytorch python=3.7

Then enter activate pytorch to activate the environment

activate pytorch

Get as shown:

2. NVIDIA driver installation and update

       1. To check the graphics card version of your computer, right-click this computer-->Manage-->Device Manager-->Display Adapter. You can see the version of your computer graphics card. As shown in the picture, you can see that mine is an RTX1650ti graphics card.

2. Go to the NVIDIA official website to download the corresponding version of the official driver | NVIDIA

       Select the corresponding product type, series, family, and operating system. There are two download types. You can choose both. Select Chinese (simplified) for the language.

3. Check the cuda version supported by the computer

Open anaconda prompt and enter nvidia-smi to get:

    As shown in the figure, you can see your driver version and the highest supported version of cuda (cuda is backward compatible). My driver version is 511.65 and the cuda version is 11.6, which means that the highest supported cuda version is 11.6.

 4. Download pytorch

Enter the official website of pytorch and scroll down to get the following picture:

       The first choice is stable, the second choice is based on your own needs, the third choice must be pip, and then choose the cuda version according to the cuda supported by the computer. There are other versions of cuda in this (pay attention to your own virtual environment) python version), and finally copy the instructions in run this command to the anaconda prompt for execution.

 5. Check whether pytorch is successfully installed

Enter python and when >>> appears, enter import torch and press Enter, enter print(torch.cuda.is_available()). If it returns true, the download is successful. Then you can enter print(torch.cuda_version) to check the version of cuda. 

Guess you like

Origin blog.csdn.net/m0_55216608/article/details/123138069