Uberfatty
Uberfatty

Reputation: 127

Cannot import torch module

I cannot seem to properly install pytorch on my computer, so here is the background of what I have done:

I had already installed python on my computer and it worked. I used it in Eclipse, using pyDev, so I don't know if that could be the problem. Now I want to install pytorch, so I installed anaconda and entered the command for installing pytorch. To get the right command, I use https://pytorch.org/get-started/locally/, where I tried the options both with and without cuda. In both cases I get an error when I type "import torch".

I have also installed miniconda and tried the same with that without succes. I also tried to work in IDLE in stead of Eclipse, but I keep getting the "no module named 'torch'" error. Each time I run a command in anaconda it appears that the installation is succesfull, but I still can't import 'torch'.

Any idea what the problem could be or what I could try?

Upvotes: 2

Views: 44736

Answers (3)

Treethap Promwiset
Treethap Promwiset

Reputation: 1

Try to create conda-env and reinstall pytorch on conda-env. Then try to import torch again.

import torch
torch.cuda.is_available()

Upvotes: 0

Minh Nguyen
Minh Nguyen

Reputation: 865

Using anaconda, I think you can check to see if pytorch is properly installed inside your conda environment using conda list inside your environment. If it is shown in the list of installed packages, you can directly try to run python in command line and import torch as in the official Pytorch tutorial:

import pytorch
torch.cuda.is_available()

For IDEs like Eclipse, you need to edit the settings of your project so that it uses the correct conda environment.

Upvotes: 0

Karan Agrawal
Karan Agrawal

Reputation: 69

Open command prompt or terminal and type: pip3 install pytorch

If it says pip isn't installed then type: python -m pip install -U pip

Then retry importing Pytorch module

Upvotes: 2

Related Questions