前提:
在pycharm中,import torch的程序都会报错:

ImportError: DLL load failed: 找不到指定的模块

并且在conda的环境下进入python终端进行import,也会报同样的错误,如下:
在这里插入图片描述
说明不是代码而是环境的问题,于是采用重装torch的方法。

首先,在conda的对应环境下输入pip uninstall torch,将旧版本的torch删除:
在这里插入图片描述
接着,用conda直接安装。首先在conda中引入镜像源:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

然后,安装pytorch(我用的是python3.6.0,选择的是0.4.0版本的pytorch)

conda install pytorch==0.4.0

再进入python终端import torch,不再报错,问题解决。
在这里插入图片描述

conda中安装torch的方法参考自:import torch时报错ImportError: DLL load failed: 找不到指定的模块。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐