4
votes

I wanted to install Pytorch via anaconda and it worked but PyCharm can't find the module (

ModuleNotFoundError: No module named 'torch'

I also have CUDA installed but when I looked up to add a the package with pycharm it also gives an error. When I added the anaconda interpreter I can't run the code. I use Python 3.6

2
This happened to me not long ago with something. Can't remember. For me it was as simple as uninstalling and reinstalling the package. Sometimes things do just get corrupted in transmission. - Thunderwood
Also which version of PyTorch are you trying to run? - Thunderwood
Did you install torchvision? - Thunderwood
yes. I ran conda install pytorch -c pytorch and pip3 install torchvision - Tinec
$conda update conda $conda install mkl=2018 - Thunderwood

2 Answers

7
votes

Ok I solved this problem: First install anaconda and open the prompt then type conda install pytorch -c pytorch and pip3 install torchvision. Then go to PyCharm and create an Project and set the Project Interpreter to the Anaconda one (there is in the path: \Anaconda.x.x\python.exe ). Then you go to the Run settings and click Run... and then you go to Edit Configurations and then you select the Project Default interpreter and apply and you should be done! Thanks to the ppl who helped me =)

0
votes

In you are on ubuntu and have installed pytorch using anaconda then in the interpreter of the pycharm which is under File -> Settings -> Interpreter you have to do following:

search for the conda where it is installed by doing where conda then in that you will find a python.exe in your environment folder provide the path of that in the python interpreter. Try with this it should work as I was facing the similar issue on windows solved it using this procedure. And probably where conda won't work if you don't have support for ubuntu commands in windows than you can go to the folder where Anaconda is there which probably will be in your Users -> 'Your User' folder in that search for you environment and in that go to your environment and find python.exe give this path in pycharm.