-
打开Anaconda中的Anaconda Navigator,如下所示:
-
修改channel环境,如下红框所示:
-
找到Jupyter Notebook的位置,点击Install,图中因为已经安装,所以是Launch,当没有下载过时,状态为Install,如下所示:
-
重启Jupyter Notebook,选择合适虚拟环境的jupyter notebook打开。输入
import torch
,如果还是显示下面结果:
在jupyter notebook界面输入conda list
,观测给出的列表中是否存在torch模块,如下所示:
如果没有存在torch模块,则通过pip重新安装已经下载好的torch-1.4.0-cp37-cp37m-win_amd64.whl
和torch-1.4.0-cp37-cp37m-win_amd64.whl
,这样就能使用torch了,具体操作如下所示:
-
总结经验
在创建的虚拟环境中通过pin安装了上面的torch-1.4.0-cp37-cp37m-win_amd64.whl
和torch-1.4.0-cp37-cp37m-win_amd64.whl
,在命令窗口中可以使用torch可以正常使用,但是在jupyter notebook中一直import torch
失败,百度了很久都没有解决这个问题,最后在jupyter notebook界面输入conda list
发现在jupyter notebook中并没有torch模块,所以在jupyter notebook界面下重新pip安装就能解决import torch
失败的问题了。