新建的环境是没有安装ipykernel的,所以无法注册到Jupyter Notebook中,所以先要准备下环境:
安装ipykernel
conda install ipykernel
写入环境
python -m ipykernel install --name torch --display-name “Pytorch for Deeplearning”
目前:::
1.新环境中安装pytorch,在终端、pycharm中import torch成功,但在jupyter中失败:ModuleNotFoundError: No module named ‘torch‘
原因:在使用Jupyter Notebook的时候,加载的仍然是默认的Python Kernel。在终端的python编译器中输入代码,查看路径;在jupyter中输入代码查看路径,可以发现二者路径不一样。
import sys
sys.executable
解决:如上安装nb_conda_kernels包。
conda install nb_conda_kernels
先activate pytorch
再jupyter notebook