Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot find module 'torch'
#1
I am getting the error message in my python program.
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-2940563e030c> in <module>
----> 1 import torch
2 # Check GPU Device
3 if IN_COLAB:
4 print(torch.cuda.get_device_name(0))

ModuleNotFoundError: No module named 'torch'
I have installed pytorch 1.6.0 and torchvision 0.7.0 and I have python 3.7.6.

The original code can be seen in the error message.

My operating system is Windows 10 Professional.

Yet, I am still getting this error.

How do I fix this?

Any help appreciated. Thanks in advance.
Respectfully,

ErnestTBass
Reply
#2
How did you install the module?  Do you have multiple python installations?  It's possible that you've installed it in one installation, but are actually running a different one.

How are you running your test program?  Are you running python explicitly, or letting the system find python by running the script from the command line or from explorer?
Reply
#3
check: python -V
           pip -V
           pip list

does everything match? and do you see pytorch in the list?
Reply
#4
Now this is very strange. I installed pytorch and torch vision with the conda command  

conda install torchvision, pytorch

etc.

When I do conda list it shows both torchvision and pytorch. Now when I do pip list it shows only torchvision, no pytorch is listed.
What is going on?

I prefer the conda command over the pip command (force of habit, I guess). I cannot explain what happens to pytorch when I use pip list.

I know from reading all of the websites saying how to deal with this error that there seem to be many answers as to how and solve it. 

Anyway :

python  -V  = 3.7.6
pytorch -V  = 1.6.0
pip -V = 20.2


It seems that there must be an inconsistency between the two commands. That being said how do I fix it?

Any help appreciated.Thanks in advance.

Respectfully,

ErnestTBass
Reply
#5
Examine your PATH.  You probably have other python installations ahead of the anaconda installation.
Reply
#6
You means the windows path such as 

echo %PATH%

I assume.

Respectfully,

ErnestTBass
Reply
#7
Here i my path for my Windows 10 Pro install. 

C:\Users\Newport_j\anaconda3\condabin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Gow\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\AMD APP SDK\3.0\bin\x86_64;C:\Program Files (x86)\AMD APP SDK\3.0\bin\x86;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Users\Newport_j\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\Newport_j\AppData\Local\Programs\Python\Python37\;C:\Users\Newport_j\AppData\Local\Microsoft\WindowsApps;

It seems Anaconda is in front of about everything. 

I am curious as to why pytorch showed upon "conda list" and did not show up on "pip list". 

It seems pytorch would show up after both commands.

What is happening when this occurs?

Respectfully,

ErnestTBass
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pip lists the module but python does not find it Dato 2 1,265 Apr-13-2023, 06:40 AM
Last Post: Dato
  unable to find module in su mode? korenron 2 1,901 Jan-10-2021, 07:41 PM
Last Post: Gribouillis
  how to find module in installed packages keuninkske 3 3,185 May-09-2020, 10:21 PM
Last Post: keuninkske
  Unable to find an existing module arbiel 2 4,938 Apr-11-2020, 07:12 PM
Last Post: arbiel
  Pycharm Cannot Find Pygame Module Myang123 2 5,976 Aug-07-2019, 01:26 AM
Last Post: Myang123
  How to find functions or methods in a module? deepakdeshp 8 4,227 May-23-2019, 09:36 AM
Last Post: DeaD_EyE
  Python can't find module installed in anaconda iFunKtion 12 54,424 Mar-06-2019, 05:15 PM
Last Post: jwsmallz
  [split] can't find '__main__' module Blue Dog 1 9,461 Oct-18-2016, 12:23 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020