10

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'

3 Answers 3

11
pip uninstall torch

then pip install torch worked for me.

Sign up to request clarification or add additional context in comments.

3 Comments

Not worked for me! I don't think simply uninstalling and then re-installing the package is a good idea at all. There should be some fundamental reason why this wouldn't work even when it's already been installed!
@inverted_index torch is a rather big package. I ran out of disk space mid installation, which a reinstallation helped fix. I'm not saying this is what caused OP's issue, but it did solve my specific situation
It worked for me because this made an update of torch. So try to pay attention to the version or torch for this kind of issue.
0

I encountered the same problem because I updated my python from 3.5 to 3.6 yesterday. I think the connection between Pytorch and Python is not correctly changed. Thus, I installed Pytorch for 3.6 again and the problem is solved. Check the install command line here[1].

1 Comment

Indeed, I too downloaded Python 3.6 after some awkward mess-ups... in retrospect what could have happened is that I download pytorch on an old version of Python and then reinstalled a newer version. Perhaps that's what caused the issue. I'll have to attempt this when I get home :)
0

I have also the same problem... All I did to fix this problem was to change the interpreter in my Visual Studio Code to Python 3.11.4 ('Base') this python version is the version used in Anaconda Navigator then I opened my Anaconda Navigator and I launched the Jupyter then I created a new file then I type pip install torch. And now my problem is solved

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.