Skip to content
Advertisement

No module named “Torch”

I successfully installed pytorch via conda:

JavaScript

I also successfully installed pytorch via pip:

JavaScript

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”

Advertisement

Answer

Try to install PyTorch using pip:

First create a Conda environment using:

JavaScript

Activate the environment using:

JavaScript

Now install PyTorch using pip:

JavaScript

Note: This will install both torch and torchvision.

Now go to Python shell and import using the command:

JavaScript
Advertisement