user16612111
user16612111

Reputation:

How to install pytorch with CUDA support with pip in Visual Studio

I am trying to install torch with CUDA enabled in Visual Studio environment. I right clicked on Python Environments in Solution Explorer, uninstalled the existing version of Torch that is not compiled with CUDA and tried to run this pip command from the official Pytorch website. The command is:

pip3 install torch==1.10.0+cu102 torchvision==0.11.1+cu102 torchaudio===0.10.0+cu102 -f https://download.pytorch.org/whl/cu102/torch_stable.html

Visual Studio reports this error Looking in links: https://download.pytorch.org/whl/cu102/torch_stable.html ERROR: Could not find a version that satisfies the requirement pip3 (from versions: none) ERROR: No matching distribution found for pip3.

I have seen similar questions asked on this site but some are circumventing on Conda while others did have unclear answers which were not accepted so I was in doubt whether to follow the answers or not. I have a very important project I need to present and I can't do that unless I install torch with cuda enabled, Please Help me and Thanks.

Upvotes: 15

Views: 178270

Answers (5)

Jeffrey Kilelo
Jeffrey Kilelo

Reputation: 6473

I encountered the same issue in my windows machine, and this is what worked for me:

  1. Uninstalled the old pytorch that has no cuda - pip uninstall torch torchvision torchaudio
  2. Installed afresh, with cuda support - pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

Upvotes: 4

mbuc91
mbuc91

Reputation: 1552

I followed the main instructions for installing on pytorch's site but still failed to have success. For my setup this resulted in pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117.

I had to add --upgrade --force-reinstall which finally fixed the problem.

Upvotes: 27

gscampa
gscampa

Reputation: 51

+cu117I still kept having the same problem until adding --no-cache-dir, pip kept installing another cached version. The following command solved the problem for me. Had to use == for torch version and >= for torchvision and torchaudio because there isn't a package that contains 1.13.1, 0.13.1, 0.13.1 with cu117

pip3 install torch==1.13.1+cu117 torchvision>=0.13.1+cu117 torchaudio>=0.13.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117 --no-cache-dir 

Upvotes: 5

Javier Morales
Javier Morales

Reputation: 31

This line of code worked for me in anaconda and windows11:

pip install torch>=1.13.0+cu116 torchvision>=0.13.0+cu116 torchaudio>=0.13.0 --extra-index-url https://download.pytorch.org/whl/cu116

Upvotes: 3

praveen pravii
praveen pravii

Reputation: 233

You can check in the pytorch previous versions website. First, make sure you have cuda in your machine by using the nvcc --version command

pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

Upvotes: 10

Related Questions