Visual Studio Code - no module name 'torch'

Hi, I am very new to computer science and I need some help with importing torch into VSC. I am unsure why but I can only import torch in the terminal, not into the main.

1 Like

You have two Python environments, one based on conda and other installed by VS. And PyTorch is installed in the first one. Since you are using VS Code, you could first install the Python extension (Press ctrl+shift+x and type in Python) and then in the left side of the status bar, it will let you select the preferred python environment.

1 Like

I already have the python extension installed. Previously when I was trying out pytorch, it was working normally. Until when I was running some image recognition codes, It prompt me to install a few more extension (which I did), and after installing, my python env doesn’t detect torch anymore.

Any idea what happened?

Change your Pthon env by clicking here and selecting the right one.

3 Likes

Thank you so much! Really appreciate your help

Hey I have the same problem and I got the base:conda but still doesn’t work.

image

Actually, nevermind it works now after I restarted.

Hi, where exactly is this?