ModuleNotFoundError: No module named 'torch'

quoniammm: <pre><code class="lang-auto">(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.
&gt;&gt;&gt; import torch
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ModuleNotFoundError: No module named 'torch'
&gt;&gt;&gt; 
</code></pre>
<p>why can I import torch by this?<br>
I can use torch in notebook.<br>
what’s the reason of it?</p>

alexis-jacq: <p>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.</p>

quoniammm: <p>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.</p>

alexis-jacq: <p>Then it seems that pytorch is not installed in that environment.</p>
<p>How did you install it?</p>

poornima_Vineeth: <p>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:</p>
<ul>
<li>pytorch=0.1.12</li>
</ul>
<p>Current channels:</p>
<ul>
<li><a href="https://conda.anaconda.org/peterjc123/win-64" rel="nofollow noopener">https://conda.anaconda.org/peterjc123/win-64</a></li>
<li><a href="https://conda.anaconda.org/peterjc123/noarch" rel="nofollow noopener">https://conda.anaconda.org/peterjc123/noarch</a></li>
<li><a href="https://repo.anaconda.com/pkgs/main/win-64" rel="nofollow noopener">https://repo.anaconda.com/pkgs/main/win-64</a></li>
<li><a href="https://repo.anaconda.com/pkgs/main/noarch" rel="nofollow noopener">https://repo.anaconda.com/pkgs/main/noarch</a></li>
<li><a href="https://repo.anaconda.com/pkgs/free/win-64" rel="nofollow noopener">https://repo.anaconda.com/pkgs/free/win-64</a></li>
<li><a href="https://repo.anaconda.com/pkgs/free/noarch" rel="nofollow noopener">https://repo.anaconda.com/pkgs/free/noarch</a></li>
<li><a href="https://repo.anaconda.com/pkgs/r/win-64" rel="nofollow noopener">https://repo.anaconda.com/pkgs/r/win-64</a></li>
<li><a href="https://repo.anaconda.com/pkgs/r/noarch" rel="nofollow noopener">https://repo.anaconda.com/pkgs/r/noarch</a></li>
<li><a href="https://repo.anaconda.com/pkgs/msys2/win-64" rel="nofollow noopener">https://repo.anaconda.com/pkgs/msys2/win-64</a></li>
<li><a href="https://repo.anaconda.com/pkgs/msys2/noarch" rel="nofollow noopener">https://repo.anaconda.com/pkgs/msys2/noarch</a></li>
</ul>
<p>After that i tried with the below commmand<br>
conda create --name pytorch</p>
<p>activate pytorch</p>
<p>conda install pytorch cuda92 -c pytorch</p>
<p>and got the below  error</p>
<p>active environment : pytorch</p>
<p>active env location : C:\Users\Vineeth\Anaconda3\envs\pytorch</p>
<p>shell level : 2</p>
<p>user config file : C:\Users\Vineeth.condarc</p>
<p>populated config files : C:\Users\Vineeth.condarc</p>
<p>conda version : 4.6.2</p>
<p>conda-build version : not installed</p>
<p>python version : 3.6.8.final.0</p>
<p>base environment : C:\Users\Vineeth\Anaconda3  (writable)</p>
<p>channel URLs : <a href="https://conda.anaconda.org/pytorch/win-64" rel="nofollow noopener">https://conda.anaconda.org/pytorch/win-64</a><br>
<a href="https://conda.anaconda.org/pytorch/noarch" rel="nofollow noopener">https://conda.anaconda.org/pytorch/noarch</a><br>
<a href="https://repo.anaconda.com/pkgs/main/win-64" rel="nofollow noopener">https://repo.anaconda.com/pkgs/main/win-64</a><br>
<a href="https://repo.anaconda.com/pkgs/main/noarch" rel="nofollow noopener">https://repo.anaconda.com/pkgs/main/noarch</a><br>
<a href="https://repo.anaconda.com/pkgs/free/win-64" rel="nofollow noopener">https://repo.anaconda.com/pkgs/free/win-64</a><br>
<a href="https://repo.anaconda.com/pkgs/free/noarch" rel="nofollow noopener">https://repo.anaconda.com/pkgs/free/noarch</a><br>
<a href="https://repo.anaconda.com/pkgs/r/win-64" rel="nofollow noopener">https://repo.anaconda.com/pkgs/r/win-64</a><br>
<a href="https://repo.anaconda.com/pkgs/r/noarch" rel="nofollow noopener">https://repo.anaconda.com/pkgs/r/noarch</a><br>
<a href="https://repo.anaconda.com/pkgs/msys2/win-64" rel="nofollow noopener">https://repo.anaconda.com/pkgs/msys2/win-64</a><br>
<a href="https://repo.anaconda.com/pkgs/msys2/noarch" rel="nofollow noopener">https://repo.anaconda.com/pkgs/msys2/noarch</a><br>
package cache : C:\Users\Vineeth\Anaconda3\pkgs<br>
C:\Users\Vineeth.conda\pkgs<br>
C:\Users\Vineeth\AppData\Local\conda\conda\pkgs<br>
envs directories : C:\Users\Vineeth\Anaconda3\envs<br>
C:\Users\Vineeth.conda\envs<br>
C:\Users\Vineeth\AppData\Local\conda\conda\envs<br>
platform : win-64<br>
user-agent : conda/4.6.2 requests/2.21.0 CPython/3.6.8 Windows/10 Windows/10.0.16299<br>
administrator : False<br>
netrc file : None<br>
offline mode : False</p>
<p>How to install torch in anaconda? is it different from pytorch?<br>
what is the command to install torch?</p>

ptrblck: <p>PyTorch <code>0.1.12</code> is really old by now and I would recommend to install the current stable release (<code>1.0</code>).<br>
Have a look at <a href="https://pytorch.org/get-started/locally/" rel="nofollow noopener">the website</a> for all install commands (including for Windows).</p>

poornima_Vineeth: <p>I have tried  that too and got the same error as before.</p>

ptrblck: <p>Could you update <code>conda</code> using <code>conda update conda</code> and try the install steps again?</p>

poornima_Vineeth: <p>I updated conda and got the result as<br>
(base) C:\Users\Vineeth&gt;conda update conda<br>
Collecting package metadata: done<br>
Solving environment: done</p>
<h1>All requested packages already installed.</h1>
<p>After that i run below command<br>
conda install pytorch torchvision -c pytorch<br>
Got the same error as before</p>

ptrblck: <p>That’s strange.<br>
Based on the logs you’ve provided it looks like you are using:</p>
<ul>
<li>Windows 10 - 64bit</li>
<li>Python 3.6</li>
</ul>
<p>Is that correct?</p>
<p>I don’t have a Windows machine here, so I can’t test it right now.</p>

poornima_Vineeth: <p>yes im using windows 10 -64 bit and python3.6</p>

poornima_Vineeth: <p>Sir may i know how that issue can be solved</p>

poornima_Vineeth: <p>Im doing in anaconda prompt itself.</p>

Tony-Y: <p>You might have missed setting the environment option <code>-n pytorch</code>.</p>
<pre><code class="lang-auto">conda install -n pytorch pytorch cuda92 -c pytorch
</code></pre>

poornima_Vineeth: <p>I’m getting the same error report  again</p>

Tony-Y: <p>As written in <a href="https://github.com/pytorch/pytorch/releases/tag/v1.0.1" rel="nofollow noopener">Bug Fix Release</a>, <code>cudatoolkit=9.0</code> must be used instead of <code>cuda92</code>.</p>
<pre><code class="lang-auto">conda install -n pytorch pytorch torchvision cudatoolkit=9.0 -c pytorch
</code></pre>

poornima_Vineeth: <p>no way sir i’m not getting it…same errors as usual</p>

poornima_Vineeth: <p>i have tried this command also<br>
conda install pytorch cudatoolkit=10.0 -c pytorch</p>

Tony-Y: <p>You can check installed packages in the environment <code>pytorch</code>:</p>
<pre><code class="lang-auto">conda list -n pytorch
</code></pre>
<p>Post the package list.</p>

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