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

喜夏-厌秋 提交于 2021-02-08 12:41:11

问题


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'


回答1:


pip uninstall torch

then pip install torch worked for me.




回答2:


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].



来源:https://stackoverflow.com/questions/50203945/no-module-named-torch-or-torch-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!