pytorch runs in anaconda prompt but not in python idle

Question:

I know this question might be stupid, but I couldn’t find any help on the internet. Recently I installed anaconda in my computer, it runs Windows 10 x64. Then I used anaconda prompt to download and install pytorch for 3.6 python:

conda install pytorch torchvision cuda100 -c pytorch

After the installation I verified in anaconda’s prompt that pytorch is installed:

>>> Python
>>> Import torch
>>> torch.cuda.is_available()
True

I also checked conda list and indeed pytorch is installed in my machine.
However, I write Python code in python 3.6.7 IDLE, not in anaconda prompt, so, whenever I try to import pytorch I get the message:

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pytorch
ModuleNotFoundError: No module named 'pytorch'

For some reason, Anacoda prompt recognizes pytorch, but not IDLE. Is there any solution for this? Is there any way to import pytorch module to IDLE?
Thanks in advance.

Asked By: LazyAnalyst

||

Answers:

It seems like the python used by idle is not the one from anaconda. In python it’s very common to have multiple environments, and you always need to be aware of which environment is activated. To see what environment is activated, you can do something in this in anaconda and idle

>>> import sys
>>> print(sys.executable)

If they have different paths, you need to first figure out how to stay in a specific environment in idle.

Answered By: bombs

did you type "import torch" in Anaconda prompt but "import pytorch" in idle?
if yes, that is simply the issue, so type "import torch" in any idle not

Answered By: Pouyan Shafaat