Reputation: 11
I just installed PyCharm and Anaconda. I installed PyTorch to Anaconda and i can even use "import torch" in Anaconda. I've created a new Project in PyCharm with the Anaconda Interpreter but i still can't use PyTorch in PyCharm.
Upvotes: 1
Views: 9128
Reputation: 555
Finally solved this in Windows 10 after sinking an entire morning into it.
C:\Your\Environment\Path\Scripts
in a command terminal
C:\ProgramData\Anaconda3\envs\Snek_V2\Scripts
pip
install from the PyTorch website
pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp37-cp37m-win_amd64.whl
pip3 install torchvision
pip3
with pip.exe
. As you've navigated to the exact environment you plan to work in, this will be the pip
relevant to you.
pip.exe install torchvision
import torch
and not have any errors pop up in response.Upvotes: 0
Reputation: 61
I had this problem also. Program that imported torch worked fine at anaconda prompt running in my pytorch env, but when i ran pycharm from the windows shortcut and EVEN set my environment to use pytorch env, it would complain torch could not be imported. When i ran pycharm from the prompt as shown, it worked.
Upvotes: 1
Reputation: 16
I got same problem and solved it:
Upvotes: 0
Reputation: 1
I got the same problem and you that how i solved the problem: 1- when you open project choose conda as your project interpreter as shown here
2- in your project go to setting -> project: project name -> Project Interpreter check that you are using Conda Package Manager and your anaconda local settings
Upvotes: 0
Reputation: 3405
If you used a bash script and the conda environment to run python codes in your PyCharm IDE.
You also need source activate myenv
in your bash script.
Like this:
#!/usr/bin/env bash
source activate myenv
python test.py
source deactivate
Upvotes: 0