# Visual Studio Code - no module name 'torch'

**URL:** <https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797>\
**Category:** Uncategorized\
**Created:** [July 11, 2020, 12:54pm UTC](https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797 "2020-07-11T12:54:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liew\_Shaun\_Kheng](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/liew_shaun_kheng/32/26577_2.png) [@Liew\_Shaun\_Kheng](https://discuss.pytorch.org/u/Liew_Shaun_Kheng)\
**Post date:** [July 11, 2020, 12:54pm UTC](https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797/1 "2020-07-11T12:54:57Z")

</div>

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](https://discuss.pytorch.org/uploads/default/original/3X/5/2/526e5ad40dc3101bc3c761c9a8b40632efbfb874.png)

---

<div class="post-metadata">

**Author:** ![peterjc123](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/peterjc123/32/2790_2.png) [@peterjc123](https://discuss.pytorch.org/u/peterjc123)\
**Post date:** [July 11, 2020, 1:54pm UTC](https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797/2 "2020-07-11T13:54:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Liew\_Shaun\_Kheng](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/liew_shaun_kheng/32/26577_2.png) [@Liew\_Shaun\_Kheng](https://discuss.pytorch.org/u/Liew_Shaun_Kheng)\
**Post date:** [July 12, 2020, 2:44am UTC](https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797/3 "2020-07-12T02:44:47Z")

</div>

![image](https://discuss.pytorch.org/uploads/default/original/3X/e/c/ec8467402c691f3c9bb1888d39950a857ea80bcb.png)

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?

---

<div class="post-metadata">

**Author:** ![Shisho\_Sama](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/shisho_sama/32/6926_2.png) [@Shisho\_Sama](https://discuss.pytorch.org/u/Shisho_Sama)\
**Post date:** [July 12, 2020, 3:53am UTC](https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797/4 "2020-07-12T03:53:45Z")

</div>

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

 ![image](https://discuss.pytorch.org/uploads/default/original/3X/f/4/f46a7437c14a2adbb2154d87c0397f970006ef1f.png)

---

<div class="post-metadata">

**Author:** ![Liew\_Shaun\_Kheng](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/liew_shaun_kheng/32/26577_2.png) [@Liew\_Shaun\_Kheng](https://discuss.pytorch.org/u/Liew_Shaun_Kheng)\
**Post date:** [July 13, 2020, 10:10am UTC](https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797/5 "2020-07-13T10:10:09Z")

</div>

Thank you so much! Really appreciate your help

---

<div class="post-metadata">

**Author:** ![Electronic\_Tears](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/electronic_tears/32/26673_2.png) [@Electronic\_Tears](https://discuss.pytorch.org/u/Electronic_Tears)\
**Post date:** [July 14, 2020, 3:12am UTC](https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797/6 "2020-07-14T03:12:48Z")

</div>

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

![image](https://discuss.pytorch.org/uploads/default/original/3X/1/7/172498eda942205e18777ed779df9e524731500b.png)

---

<div class="post-metadata">

**Author:** ![Electronic\_Tears](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/electronic_tears/32/26673_2.png) [@Electronic\_Tears](https://discuss.pytorch.org/u/Electronic_Tears)\
**Post date:** [July 15, 2020, 1:00am UTC](https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797/7 "2020-07-15T01:00:52Z")

</div>

Actually, nevermind it works now after I restarted.

---

<div class="post-metadata">

**Author:** ![Ansh\_Shah](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ansh_shah/32/46825_2.png) [@Ansh\_Shah](https://discuss.pytorch.org/u/Ansh_Shah)\
**Post date:** [February 18, 2022, 9:00pm UTC](https://discuss.pytorch.org/t/visual-studio-code-no-module-name-torch/88797/8 "2022-02-18T21:00:08Z")

</div>

Hi, where exactly is this?
