Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't import torch in vscode despite having anaconda interpreter and torch installed

I have both python38,37 and anaconda installed, OS - win10,x64.

I could not install torch in py38,37 - but installed it in anaconda.

system env var 'Path' has:

  • C:\python38\Scripts\
  • C:\python38\
  • C:\python37\Scripts\
  • C:\python37\
  • C:\anaconda3\
  • C:\anaconda3\Scripts

In vscode, despite that i have selected interpreter as Python 3.8.3 base-conda

enter image description here

I still can't import torch. But when using jupyter notebook, I can import torch:

import torch
print(torch.__path__)

['C:\\anaconda3\\lib\\site-packages\\torch']

How to import torch in vs code and choose the right interpreter?

like image 868
ERJAN Avatar asked Sep 19 '25 22:09

ERJAN


1 Answers

When we import the module, we need to install the required module in the currently selected environment.(Python environments.)

I installed it in the base conda environment using the following statement:

conda install pytorch torchvision -c pytorch

enter image description here

We need to pay attention to the selected kernel in Jupyter Notebook:

enter image description here

like image 179
Jill Cheng Avatar answered Sep 21 '25 10:09

Jill Cheng