title: How can I fix this pytorch error on Windows? (ModuleNotFoundError: No module named 'torch')
body: <p><strong>Edit:</strong> You might want to skip to the end of the question first, I've followed some advice in comments / answers and the current error is different from the original (appears to be related to numpy possibly).</p>
  
  <p>This error <code>ModuleNotFoundError: No module named 'torch'</code> shows up in tons of threads, I've been trying solutions all day. I'll go through my troubleshooting steps one by one, using the solutions suggested in threads.</p>
  
  <p>System info:
  Windows 10</p>
  
  <p><a href="https://i.stack.imgur.com/DNG6a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DNG6a.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/1PgUg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1PgUg.png" alt="enter image description here"></a></p>
  
  <p>First thing I did was follow the instructions on Pytorch, installed Anaconda and did this using the correct settings for my machine (<strong>Note</strong>: I tried Python v3.7 before trying v3.8 in these screenshots, none of the solutions worked with that either):</p>
  
  <p><a href="https://i.stack.imgur.com/nlkht.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nlkht.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/zFclJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zFclJ.png" alt="enter image description here"></a></p>
  
  <p>As you can see, that should be good to go, according to the instructions.</p>
  
  <p>So I go into the python terminal and try to import pytorch, like so:</p>
  
  <p><a href="https://i.stack.imgur.com/mtRSa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mtRSa.png" alt="enter image description here"></a></p>
  
  <p><code>ModuleNotFoundError: No module named 'torch'</code> Great, so what now? Well I paste the error into Google and begin my 4 hour wild goose chase. </p>
  
  <p>First result, stack overflow answer: <a href="https://stackoverflow.com/questions/54843067/no-module-named-torch">No module named &quot;Torch&quot;</a>
   Let's try the selected answer, it requires some version-related syntax so lets check my python version:</p>
  
  <p><a href="https://i.stack.imgur.com/7d3FS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7d3FS.png" alt="enter image description here"></a></p>
  
  <p>Alright so as directed by the answer:</p>
  
  <blockquote>
    <p>Try to install PyTorch using pip:</p>
    
    <p>First create a conda environment using:</p>
  
  <pre><code>conda create -n env_pytorch python=3.6
  </code></pre>
  </blockquote>
  
  <p>Ok:</p>
  
  <p><a href="https://i.stack.imgur.com/lHjxf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lHjxf.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>Activate the environment using:</p>
  
  <pre><code>source activate env_pytorch
  </code></pre>
  </blockquote>
  
  <p>That doesnt work, but if we activate using the instructions given by the prompt, we can do so:</p>
  
  <p><a href="https://i.stack.imgur.com/mUbKM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mUbKM.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>Now install PyTorch using pip:</p>
  
  <pre><code>pip install torchvision --user ( this will install both torch and torchvision)
  </code></pre>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/3UziJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3UziJ.png" alt="enter image description here"></a></p>
  
  <p>Hmmm.. well that went up in flames, so the following...</p>
  
  <blockquote>
    <p>Now go to python shell and import using the command:</p>
  
  <pre><code>import torch
  import torchvision
  </code></pre>
  </blockquote>
  
  <p>...doesn't do anything new, same error as before.</p>
  
  <p>Well, to the next thread, on PyTorch GitHub: <a href="https://github.com/pytorch/pytorch/issues/4827" rel="nofollow noreferrer">https://github.com/pytorch/pytorch/issues/4827</a></p>
  
  <p>They're trying to use Jupyter, so I tried this, is was another long process like the above that went up in flames, and I really dont want to need to use Jupyter anyway, so we'll skip this one.</p>
  
  <p>Another Pytorch GitHub thread: <a href="https://github.com/pytorch/pytorch/issues/12004" rel="nofollow noreferrer">https://github.com/pytorch/pytorch/issues/12004</a></p>
  
  <blockquote>
    <p>@edtky Could you please give me the output of the following commands
    in CMD?</p>
    
    <p>where conda.exe 
    where pip.exe 
    where python.exe</p>
  </blockquote>
  
  <p>Sure I'll give it a shot:</p>
  
  <p><a href="https://i.stack.imgur.com/3zyJr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3zyJr.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>@edtky Looks like you have two Python environments. Please try
    importing torch in Anaconda Prompt.</p>
  </blockquote>
  
  <p>Oh well, I already did that. No bueno.</p>
  
  <p>Another thread: <a href="https://discuss.pytorch.org/t/modulenotfounderror-no-module-named-torch/7309" rel="nofollow noreferrer">https://discuss.pytorch.org/t/modulenotfounderror-no-module-named-torch/7309</a> suggests:</p>
  
  <blockquote>
    <p>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>
  </blockquote>
  
  <p>Well I did activate the environment as shown above, but I dont know anything about a PYTHONPTH variable, seems like the PyTorch setup guide wouldve mentioned if I needed to manually do that, I have no clue how to do it and you aren't explaining, so lets look for other answers.</p>
  
  <p>Someone made a whole article to give us this little gym of advice: <a href="https://medium.com/@valeryyakovlev/anaconda-no-module-named-torch-ead10946de66" rel="nofollow noreferrer">https://medium.com/@valeryyakovlev/anaconda-no-module-named-torch-ead10946de66</a></p>
  
  <blockquote>
    <p>Another beginner error I encountered when started to use pytorch in
    anaconda environment
        import torch ModuleNotFoundError: No module named ‘torch’ the proper way to install pytorch to anaconda is following
        conda install -c pytorch pytorch It’s not enough to simply run “conda install pytorch” — the package won’t be found. So first
    activate your conda profile with “source activate {your_profile}” and
    then run the <code>command conda install -c...</code></p>
  </blockquote>
  
  <p>Ok thats new info, let's try that command again now that our env is activated:</p>
  
  <p><a href="https://i.stack.imgur.com/m084P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m084P.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/0OQEF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0OQEF.png" alt="enter image description here"></a></p>
  
  <p>Ok that's a lot of green, let's try now...</p>
  
  <p><a href="https://i.stack.imgur.com/m5lgz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m5lgz.png" alt="enter image description here"></a></p>
  
  <p>Well we can't win 'em all, so lets go onto the next thread: <a href="https://forums.fast.ai/t/modulenotfounderror-no-module-named-torch-windows-10/12438/2" rel="nofollow noreferrer">https://forums.fast.ai/t/modulenotfounderror-no-module-named-torch-windows-10/12438/2</a></p>
  
  <blockquote>
    <p>I had also faced the similar problem , I just installed torch and torchvision using pip and it worked …</p>
  </blockquote>
  
  <p>Ok! Let's try:</p>
  
  <p><a href="https://i.stack.imgur.com/eOVGA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eOVGA.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/yDA08.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yDA08.png" alt="enter image description here"></a></p>
  
  <p>Oh well, another solution up in flames..</p>
  
  <blockquote>
    <p>I ran into a similar issue with Windows 10. In the end I could only get torch installed with Miniconda.</p>
  </blockquote>
  
  <p>Alrighty, lets try it! </p>
  
  <p><a href="https://i.stack.imgur.com/JXM3S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JXM3S.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/YbFfF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YbFfF.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/YsGRl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YsGRl.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/4V4Nb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4V4Nb.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/S3INy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S3INy.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/gdsvW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gdsvW.png" alt="enter image description here"></a></p>
  
  <p>Alright, cool, moment of truth:</p>
  
  <p><a href="https://i.stack.imgur.com/B28Zq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B28Zq.png" alt="enter image description here"></a></p>
  
  <p>Awesome! You just read through 25 minutes of me re-producing all my attempts to solve this problem, and it doesnt even include the hour I spend down a rabbit hole trying to use Jupyter, which failed equally as miserably. I think it's time to post the question to StackOverflow!</p>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>An answer points out that one of my logs was an error python 3.8 isn't compatible with pytorch, good point I'll fix that. After unintalling 3.8 and installing 3.7:</p>
  
  <p><a href="https://i.stack.imgur.com/pVkmE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pVkmE.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/B8bJ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B8bJ2.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/5tuk3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5tuk3.png" alt="enter image description here"></a></p>
  
  <p>And no luck! Remember I actually mentioned in my first paragraph that while I was trying 3.8 in these screenshots, the first time around I did all of this with 3.7</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>I forgot to install <em>after</em> activating the environment in the previous edit. Once I fixed that, there's a new error:</p>
  
  <p><a href="https://i.stack.imgur.com/nINz5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nINz5.png" alt="enter image description here"></a></p>