安装pytorch运行import torch出错ModuleNotFoundError: No module named ‘torch’
程序员文章站
2022-05-28 22:27:41
...
安装pytorch运行import torch出错ModuleNotFoundError: No module named ‘torch’
这种情况的出现属于版本不匹配问题,目测应该是你的系统中有多个版本的python导致指向错误或者conda没有升级,在官网可以查到你想要的版本,在这里就不列举了。
直接运行以下代码即可解决问题
conda update conda
conda install mkl=2018
安装好之后检测一下
python
import torch
torch.__version__
C:\Users\Administrator>python
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.7.1'
>>>
显示安装成功
推荐阅读
-
ModuleNotFoundError: No module named 'torch'(anaconda安装好Pytorch却无法在Jupyter notebook使用)
-
安装pytorch运行import torch出错ModuleNotFoundError: No module named ‘torch’
-
pytorch的ModuleNotFoundError: No module named 'torch'
-
Pytorch: ModuleNotFoundError: No module named 'torch_scatter.scatter_cpu'
-
Mac在jupyter notebook上import torch出错:ModuleNotFoundError: No module named 'torch'