pycharm installs torch and cuda (in the new environment created by anaconda)

1. The problem

There seems to be some conflict between torch and tensorflow in pycharm, so I created two conda environments (one named pytorch, one named tensorflow). There is no tensorflow library in the pytorch environment, and the same is true for the tensorflow environment.

The problem now is that every time I use pip install torch in Terminal, it is always the cpu version.

pip install torch 
import torch
print(torch.__version__)
print(torch.cuda.is_available())

This code is to see whether torch uses cuda (or as I understand it, whether it uses the gpu version). The output is False, which means the cpu version.

2.Install cuda

I think many people may have CUDA installed on their computers.

You can check on your computer to see if it’s there. It’s better if it’s there. If it’s not there, let’s talk about how to download NVIDIA cuda.

(1) Check the NVIDIA version you should download

Right-click “This PC” – Manage – Device Manager – Display Adapters
This way you can find out your graphics card model.

NVIDIA graphics card driver download address:Official Advanced Driver Search | NVIDIA
Choose the model that suits you and start downloading

(2) Download the corresponding cuda version

CUDA download address:https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal
Select the appropriate model and click download

Check whether the installation is correct: win+R→cmd→nvcc -V
As shown in the picture, the installation is correct.

 

At this point, CUDA has been installed in your computer (if you encounter other problems in the installation diagram, you can continue to search for the problem, but this installation process must be no problem). The next step is to install the gpu version of torch

3. Install torch (in Terminal in pycharm, because I like to use this method and don’t like to use cmd or anaconda)

Open this URL directlyhttps://pytorch.org/get-started/locally/

 

I think everyone should be able to understand how to choose. Among them, I use Terminal, so I selected pip in Package. The first one I saw was Stable, which other bloggers chose. As for the last Compute Platform option, my cuda version is 11.7. So I chose this one (I heard that the version should be almost close and not so strict).

Teach you how to choose the final Compute Platform (that is, how to check your cuda version)

After right-clicking on the desktop to open the NAIDIA control panel, find the system information in the help, click on the components, and you can see CUDA 11.7.57 (meaning version 11.7) in the blue one.

 

So far I have learned to check the cuda version and downloaded the pytorch corresponding to cuda.

At this point it’s basically done, just copy the contents of the Run this Command column in the last column directly into Terminal.

4. I found that installing torch using the above method is very slow.

Very easy to solve, open the URLhttps://download.pytorch.org/whl/torch_stable.html

After entering, find the version you need. For example, I am cuda11.7+python3.7+windows, so I chose the following one.

 

cu stands for cuda (that is, choose the gpu version instead of the cpu version, be sure to look carefully here), torch1.11.0 version, I don’t think there are any special requirements for this, but I like the new version, cp37 stands for python3.7, and win stands for windows system , 64 represents 64 bits.

After downloading, I placed it in the site-package in LIB in the pytorch environment I created, and then wrote the following code in Terminal

pip install D:\anaconda\Anaconda\envs\pytorch\Lib\site-packages\torch-1.11.0+cu113-cp37-cp37m-win_amd64.whl

Code description: The file is placed in D:\anaconda\Anaconda\envs\pytorch\Lib\site-packages. The file name is torch-1.11.0+cu113-cp37-cp37m-win_amd64.whl. Just press Enter.

So far the problem has been solved, how to determine the solution?

import torch
print(torch.__version__)
print(torch.cuda.is_available())

The output is

1.11.0+cu113
True

I hope everyone can solve this kind of problem smoothly

Related Posts

python: Some problems and solutions when starting to use tensorflow

Complete interpretation of YOLOv5 network structure [source code + hand-drawn network structure + module structure]

The simplest Anaconda+Python3.7 installation tutorial on the Internet for Win10 (100% successful)

Correspondence between Tensorflow and CUDA and cudnn versions

[Pycharm2022.2.1] Latest version installation tutorial (including all versions of win/mac/linux from 2017-2022)

[Installation of Keras environment]

Detailed tutorial on installing sqlmap

The relationship between FLOPs, MACs, and MAdds of deep learning model calculation load evaluation indicators

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*