ModuleNotFoundError: No module named 'torch'

(pytorch) quoniammm@quoniammm:~/version-control/DrQA$ python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'
>>> 

why can I import torch by this?
I can use torch in notebook.
what’s the reason of it?

Are you using Anaconda? In that case you’ve probably forgotten to activate the environment where pytorch is installed. It can also be the library missing in your PYTHONPATH variable.

Yes,I use it.The pytorch is the name of env.When I use pytorch in notebook it’s ok.However,when it is in the terminal.The problem occured.I do not know why.

Then it seems that pytorch is not installed in that environment.

How did you install it?

conda install -c peterjc123 pytorch=0.1.12 while running these command i got an error saying PackagesNotFoundError: The following packages are not available from current channels:

  • pytorch=0.1.12

Current channels:

After that i tried with the below commmand
conda create --name pytorch

activate pytorch

conda install pytorch cuda92 -c pytorch

and got the below error

active environment : pytorch

active env location : C:\Users\Vineeth\Anaconda3\envs\pytorch

shell level : 2

user config file : C:\Users\Vineeth.condarc

populated config files : C:\Users\Vineeth.condarc

conda version : 4.6.2

conda-build version : not installed

python version : 3.6.8.final.0

base environment : C:\Users\Vineeth\Anaconda3 (writable)

channel URLs : https://conda.anaconda.org/pytorch/win-64
https://conda.anaconda.org/pytorch/noarch
https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/win-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\Users\Vineeth\Anaconda3\pkgs
C:\Users\Vineeth.conda\pkgs
C:\Users\Vineeth\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\Vineeth\Anaconda3\envs
C:\Users\Vineeth.conda\envs
C:\Users\Vineeth\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/4.6.2 requests/2.21.0 CPython/3.6.8 Windows/10 Windows/10.0.16299
administrator : False
netrc file : None
offline mode : False

How to install torch in anaconda? is it different from pytorch?
what is the command to install torch?

PyTorch 0.1.12 is really old by now and I would recommend to install the current stable release (1.0).
Have a look at the website for all install commands (including for Windows).

I have tried that too and got the same error as before.

Could you update conda using conda update conda and try the install steps again?

I updated conda and got the result as
(base) C:\Users\Vineeth>conda update conda
Collecting package metadata: done
Solving environment: done

All requested packages already installed.

After that i run below command
conda install pytorch torchvision -c pytorch
Got the same error as before

That’s strange.
Based on the logs you’ve provided it looks like you are using:

  • Windows 10 - 64bit
  • Python 3.6

Is that correct?

I don’t have a Windows machine here, so I can’t test it right now.

yes im using windows 10 -64 bit and python3.6

Sir may i know how that issue can be solved

Im doing in anaconda prompt itself.

You might have missed setting the environment option -n pytorch.

conda install -n pytorch pytorch cuda92 -c pytorch

I’m getting the same error report again

As written in Bug Fix Release, cudatoolkit=9.0 must be used instead of cuda92.

conda install -n pytorch pytorch torchvision cudatoolkit=9.0 -c pytorch

no way sir i’m not getting it…same errors as usual

i have tried this command also
conda install pytorch cudatoolkit=10.0 -c pytorch

You can check installed packages in the environment pytorch:

conda list -n pytorch

Post the package list.

(base) C:\Users\Vineeth>conda list -n pytorch

packages in environment at C:\Users\Vineeth\Anaconda3\envs\pytorch:

Name Version Build Channel

(base) C:\Users\Vineeth>conda list

packages in environment at C:\Users\Vineeth\Anaconda3:

Name Version Build Channel

_license 1.1 py36_1
alabaster 0.7.10 py36_0
anaconda custom py36h363777c_0
anaconda-client 1.6.3 py36_0
anaconda-navigator 1.6.2 py36_0
anaconda-project 0.6.0 py36_0
asn1crypto 0.22.0 py36_0
astroid 1.4.9 py36_0
astropy 1.3.2 np112py36_0
babel 2.4.0 py36_0
backports 1.0 py36_0
beautifulsoup4 4.6.0 py36_0
bitarray 0.8.1 py36_1
blas 1.0 mkl
bleach 1.5.0 py36_0
boto 2.46.1 py36_0
boto3 1.6.18 py36_0
botocore 1.9.18 py36_0
bottleneck 1.2.1 np112py36_0
bz2file 0.98 py36_0
bzip2 1.0.6 hfa6e2cd_5
ca-certificates 2018.12.5 0
certifi 2018.11.29 py36_0
cffi 1.10.0 py36_0
chardet 3.0.3 py36_0
click 6.7 py36_0
cloudpickle 0.2.2 py36_0
clyent 1.2.2 py36_0
colorama 0.3.9 py36_0
comtypes 1.1.2 py36_0
conda 4.6.2 py36_0
conda-env 2.6.0 h36134e3_1
console_shortcut 0.1.1 py36_1
contextlib2 0.5.5 py36_0
cryptography 2.4.2 py36h7a1dbc1_0
curl 7.63.0 h2a8f88b_1000
cycler 0.10.0 py36_0
cython 0.25.2 py36_0
cytoolz 0.8.2 py36_0
decorator 4.0.11 py36_0
docutils 0.13.1 py36_0
entrypoints 0.2.2 py36_1
et_xmlfile 1.0.1 py36_0
fastcache 1.0.2 py36_1
flask 0.12.2 py36_0
flask-cors 3.0.2 py36_0
flask-wtf 0.14.2 py36_0
freetype 2.9.1 ha9979f8_1
get_terminal_size 1.0.0 py36_0
gevent 1.2.1 py36_0
greenlet 0.4.12 py36_0
h5py 2.7.0 np112py36_0
hdf5 1.10.4 h7ebc959_0
heapdict 1.0.0 py36_1
html5lib 0.999 py36_0
icc_rt 2019.0.0 h0cc432a_1
icu 58.2 ha66f8fd_1
idna 2.5 py36_0
imagesize 0.7.1 py36_0
intel-openmp 2019.1 144
ipykernel 4.6.1 py36_0
ipython 5.3.0 py36_0
ipython_genutils 0.2.0 py36_0
ipywidgets 6.0.0 py36_0
isort 4.2.5 py36_0
itsdangerous 0.24 py36_0
jdcal 1.3 py36_0
jedi 0.10.2 py36_2
jinja2 2.9.6 py36_0
jmespath 0.9.3 py36h0745840_0
jpeg 9b hb83a4c4_2
jsonschema 2.6.0 py36_0
jupyter 1.0.0 py36_3
jupyter_client 5.0.1 py36_0
jupyter_console 5.1.0 py36_0
jupyter_core 4.3.0 py36_0
krb5 1.16.1 hc04afaa_7
lazy-object-proxy 1.2.2 py36_0
libcurl 7.63.0 h2a8f88b_1000
libpng 1.6.36 h2a8f88b_0
libssh2 1.8.0 h7a1dbc1_4
libtiff 4.0.10 h2929a5b_1001
llvmlite 0.18.0 py36_0
locket 0.2.0 py36_1
lxml 3.7.3 py36_0
markupsafe 0.23 py36_2
matplotlib 2.0.2 np112py36_0
menuinst 1.4.14 py36hfa6e2cd_0
mistune 0.7.4 py36_0
mkl 2019.1 144
mkl-service 1.1.2 py36_3
mkl_fft 1.0.10 py36h14836fe_0 anaconda
mkl_random 1.0.2 py36h343c172_0
mpmath 0.19 py36_1
msgpack-python 0.4.8 py36_0
multipledispatch 0.4.9 py36_0
navigator-updater 0.1.0 py36_0
nbconvert 5.1.1 py36_0
nbformat 4.3.0 py36_0
networkx 1.11 py36_0
ninja 1.8.2 py36he980bc4_1
nltk 3.2.3 py36_0
nose 1.3.7 py36_1
notebook 5.0.0 py36_0
numba 0.33.0 np112py36_0
numexpr 2.6.2 np112py36_0
numpy 1.15.4 py36h19fb1c0_0 anaconda
numpy-base 1.15.4 py36hc3f5095_0
numpydoc 0.6.0 py36_0
olefile 0.44 py36_0
openpyxl 2.4.7 py36_0
openssl 1.1.1a he774522_0
packaging 16.8 py36_0
pandas 0.20.1 np112py36_0
pandocfilters 1.4.1 py36_0
partd 0.3.8 py36_0
path.py 10.3.1 py36_0
pathlib2 2.2.1 py36_0
pep8 1.7.0 py36_0
pickleshare 0.7.4 py36_0
pillow 5.4.1 py36hdc69c19_0
pip 9.0.1 py36_1
ply 3.10 py36_0
prompt_toolkit 1.0.14 py36_0
psutil 5.2.2 py36_0
py 1.4.33 py36_0
pycodestyle 2.3.1 py36h7cc55cd_0
pycosat 0.6.3 py36h413d8a4_0
pycparser 2.17 py36_0
pycrypto 2.6.1 py36_6
pycurl 7.43.0.2 py36h7a1dbc1_0
pyflakes 1.5.0 py36_0
pygments 2.2.0 py36_0
pylint 1.6.4 py36_1
pyodbc 4.0.16 py36_0
pyopenssl 17.0.0 py36_0
pyparsing 2.1.4 py36_0
pyqt 5.9.2 py36h6538335_2
pysocks 1.6.8 py36_0
pytables 3.2.2 np112py36_4
pytest 3.0.7 py36_0
python 3.6.8 h9f7ef89_0
python-dateutil 2.6.0 py36_0
pytz 2017.2 py36_0
pywavelets 0.5.2 np112py36_0
pywin32 220 py36_2
pyyaml 3.12 py36_0
pyzmq 16.0.2 py36_0
qt 5.9.7 vc14h73c81de_0
qtawesome 0.4.4 py36_0
qtconsole 4.3.0 py36_0
qtpy 1.2.1 py36_0
requests 2.21.0 py36_0
rope 0.9.4 py36_1
ruamel_yaml 0.11.14 py36_1
s3transfer 0.1.13 py36_0
setuptools 40.6.3 py36_0
simplegeneric 0.8.1 py36_1
singledispatch 3.4.0.3 py36_0
sip 4.19.8 py36h6538335_0
six 1.10.0 py36_0
smart_open 1.5.7 py36_0
snowballstemmer 1.2.1 py36_0
sortedcollections 0.5.3 py36_0
sortedcontainers 1.5.7 py36_0
sphinx 1.5.6 pypi_0 pypi
spyder 3.2.8 py36_0
sqlalchemy 1.1.9 py36_0
sqlite 3.26.0 he774522_0
sympy 1.0 py36_0
tblib 1.3.2 py36_0
testpath 0.3 py36_0
tk 8.6.8 hfa6e2cd_0
toolz 0.8.2 py36_0
tornado 4.5.1 py36_0
traitlets 4.3.2 py36_0
unicodecsv 0.14.1 py36_0
urllib3 1.24.1 py36_0
vc 14.1 h21ff451_3 anaconda
vs2015_runtime 15.5.2 3 anaconda
wcwidth 0.1.7 py36_0
werkzeug 0.12.2 py36_0
wheel 0.29.0 py36_0
widgetsnbextension 2.0.0 py36_0
win_inet_pton 1.0.1 py36_1
win_unicode_console 0.5 py36_0
wincertstore 0.2 py36h7fe50ca_0
wrapt 1.10.10 py36_0
wtforms 2.1 py36_0
xlrd 1.0.0 py36_0
xlsxwriter 0.9.6 py36_0
xlwings 0.10.4 py36_0
xlwt 1.2.0 py36_0
zict 0.1.2 py36_0
zlib 1.2.11 h62dcd97_3