Errors with Importing torch Using Pycharm CE

I met problem of " ModuleNotFoundError: No module named ‘torch’ , when I try to import torch in the Pycharm CE.
I tried to install the module with Pycharm but it still did not work.

However, when I try to import torch in the terminal by scrapy shell mode, “import torch” is successful.

Can someone help me out of this? Thanks

Are you using the same interpreter as the shell is? You can select project interpreter in the project settings

I used the interpreter as the pic attached since I used the anaconda to install the Pytorch. But it still does not work. The output is "ModuleNotFoundError: no module named ‘torch’ ".

I have solved the problem. Close the question.

How did you solve it. I am getting the same error: ModuleNotFoundError: No module named ‘torch’. And I am not able to fix it at all. Please help.

@Damon @bhattacharjeeajay12 I met the same problem. How did you fix it?? Please help. Many thanks!

Hello everybody,

I met the same problem.

I fix the problem, with following instructions:

1.) Install torch with the first three instruction on http://torch.ch/docs/getting-started.html

2.) Follow the instructions of pytorch.org for your specific system (But you have to add “sudo” before you paste the instructions pip3 …)

3.) After that you change your project interpreter in PyCharm, with 1) settings --> project interpreter /show all --> plus symbol --> add local --> choose your system interpreter --> Finally you change the project interpreter on system interpreter and here was the modules installed already

At the last point you can verify it by pasting the following code:

import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.nn.functional as F

If there are not any errors,that’s it!

1 Like

I still have this problem :frowning:

Thanks a lot! I have solved this problem following your suggestion. In particular, I also changed the "edit configuration" to the right interpreter, then the problem was finally solved.