Kapil
Kapil

Reputation: 113

Installed pytorch through conda, but cannot import in Windows 10

When I issue an Anaconda prompt conda search pytorch then I get pytorch installed even issuing conda list command gives me:

pytorch                   1.5.1           py3.7_cuda102_cudnn7_0    pytorch

But when I start python on command prompt and then issue import pytorch i get ModuleNotFoundError: No module named 'pytorch'.

Even I tried to do the same after issuing

conda create -n pytorch_env -c pytorch pytorch torchvision
conda activate pytorch_env
conda install -c pytorch pytorch torchvision

as written in Installing PyTorch via Conda but of no use. BTW does it require a restart of the machine after installing Anaconda? Also, let me know how I can use PyTorch in Jupyter notebooks.

Upvotes: 0

Views: 3205

Answers (1)

Mrinal Roy
Mrinal Roy

Reputation: 979

Verify the installation with import torch not pytorch. Example code below, source.

from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)

If above throws same issue in Jupyter Notebooks and if you already have GPU enabled, try restarting the Jupyter notebook server as sometimes it requires restarting, user reported.

when I tried to import this package from Jupyter notebook, I got following error message: ModuleNotFoundError: No module named 'torch'. Then, I tried installing Jupyter notebook application from Anaconda navigator for my environment(torch). Restarted my Jupyter notebook and ran import torch and this time it worked

Otherwise, you need CPU only version of PyTorch.

conda install pytorch torchvision cpuonly -c pytorch

Upvotes: 3

Related Questions