Issues with getting cuda to work on torch, importing torch and cuda modules into Python
Question:
I’m having some basic issues running the torch and cuda modules in my Python script.
I think that this has something to do with the different versions of Python that I have installed. I have two versions of Python installed:
I think I have torch and cuda installed for the wrong one or something. I don’t know how to fix this.
Per the Pytorch website, I installed torch as follows:
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
I’ve installed cuda as follows: pip3 install cuda-python==11.7
(It doesn’t matter if I use the newest version — I still get the same results.)
When I look up the versions, I get the following:
So it seems like it is all installed correctly.
However, if I run the following:
import torch
print(torch.cuda.is_available())
I get False
.
If I try to run my code that uses torch, I get the following error:
I don’t get what I’m doing wrong. As far as I can tell, I’ve installed torch with CUDA enabled. So I’m not sure why it’s telling me otherwise.
Any ideas? Thanks for any help.
Answers:
The issue had to do with the different versions of Python. I ended up using a Conda virtual environment, which solved this issue by ensuring I was using the correct version of Pytorch.
I’m having some basic issues running the torch and cuda modules in my Python script.
I think that this has something to do with the different versions of Python that I have installed. I have two versions of Python installed:
I think I have torch and cuda installed for the wrong one or something. I don’t know how to fix this.
Per the Pytorch website, I installed torch as follows:
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
I’ve installed cuda as follows: pip3 install cuda-python==11.7
(It doesn’t matter if I use the newest version — I still get the same results.)
When I look up the versions, I get the following:
So it seems like it is all installed correctly.
However, if I run the following:
import torch
print(torch.cuda.is_available())
I get False
.
If I try to run my code that uses torch, I get the following error:
I don’t get what I’m doing wrong. As far as I can tell, I’ve installed torch with CUDA enabled. So I’m not sure why it’s telling me otherwise.
Any ideas? Thanks for any help.
The issue had to do with the different versions of Python. I ended up using a Conda virtual environment, which solved this issue by ensuring I was using the correct version of Pytorch.