Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'torch' or 'torch.C'

Tags:

pytorch

Would appreciate an explanation like I'm 5 simply because I have checked all relevant answers and none have helped.

I have installed Python. I have installed Pycharm. I have installed Anaconda. I have installed Microsoft Visual Studio. I have not installed the CUDA toolkit.

In Anaconda, I used the commands mentioned on Pytorch.org (06/05/18)

conda install pytorch -c pytorch
pip3 install torchvision

Both have downloaded and installed properly, and I can find them in my Users/Anaconda3/pkgs folder, which I have added to the Python path.

Trying to enter

import torch

in the Python console proved unfruitful - always giving me the same error,

No module named 'torch'

I have also tried using the Project Interpreter to download the Pytorch package. It worked for numpy (sanity check, I suppose) but told me to go to Pytorch.org when I tried to install the "pytorch" or "torch" packages.

When trying to use the console in PyCharm, pip3 install codes (thinking maybe I need to save the packages into my current project, rather than in the Anaconda folder) return me an error message saying

torch-0.4.0-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform.

The same message shows no matter if I try downloading the CUDA version or not, or if I choose to use the 3.5 or 3.6 Python link (I have Python 3.7)

Currently the closest I have gotten to a solution, is manually copying the "torch" and "torch-0.4.0-py3.6.egg-info" folders into my current Project's lib folder. However, when I do that and then run "import torch" I received the following error:

Traceback (most recent call last):

File "", line 1, in

File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 19, in do_import

module = self._system_import(name, *args, **kwargs) File "C:\Users\Michael\PycharmProjects\Pytorch_2\venv\lib\site-packages\torch__init__.py",

line 78, in

from torch._C import *

File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 19, in do_import

module = self._system_import(name, *args, **kwargs) ModuleNotFoundError: No module named 'torch._C'

like image 457
Mikky Avatar asked May 06 '18 19:05

Mikky


1 Answers

pip uninstall torch

then pip install torch worked for me.

like image 110
Samuel Mideksa Avatar answered May 24 '23 16:05

Samuel Mideksa