Jupyter notebook中怎么添加Pytorch运行环境

  1. 打开Anaconda中的Anaconda Navigator,如下所示:

    Jupyter notebook中怎么添加Pytorch运行环境_第1张图片

  2. 修改channel环境,如下红框所示:

    Jupyter notebook中怎么添加Pytorch运行环境_第2张图片

  3. 找到Jupyter Notebook的位置,点击Install,图中因为已经安装,所以是Launch,当没有下载过时,状态为Install,如下所示:

    Jupyter notebook中怎么添加Pytorch运行环境_第3张图片

  4. 重启Jupyter Notebook,选择合适虚拟环境的jupyter notebook打开。输入import torch,如果还是显示下面结果:
    在这里插入图片描述
    在jupyter notebook界面输入conda list,观测给出的列表中是否存在torch模块,如下所示:Jupyter notebook中怎么添加Pytorch运行环境_第4张图片
    如果没有存在torch模块,则通过pip重新安装已经下载好的torch-1.4.0-cp37-cp37m-win_amd64.whltorch-1.4.0-cp37-cp37m-win_amd64.whl,这样就能使用torch了,具体操作如下所示:
    Jupyter notebook中怎么添加Pytorch运行环境_第5张图片

  5. 总结经验
    在创建的虚拟环境中通过pin安装了上面的torch-1.4.0-cp37-cp37m-win_amd64.whltorch-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失败的问题了。

你可能感兴趣的:(pytorch)