No module named “Torch”


I successfully installed pytorch via conda:

conda install pytorch-cpu torchvision-cpu -c pytorch

I also successfully installed pytorch via pip:

pip3 install
pip3 install torchvision

But, it only works in a jupyter notebook. Whenever I try to execute a script from the console, I get the error message:

No module named "torch"


Try to install PyTorch using pip:

First create a Conda environment using:

conda create -n env_pytorch python=3.6

Activate the environment using:

conda activate env_pytorch

Now install PyTorch using pip:

pip install torchvision 

Note: This will install both torch and torchvision.

Now go to Python shell and import using the command:

import torch
import torchvision


Leave a Reply

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