win10环境conda安装jupyter-lab和kernel

提要

我们可以通过conda创建多个python环境,在使用时通过activate 命令切换环境.在使用jupyterlab的时候我们需要在不同环境间切换来运行代码,因此需要创建多个jupyter的kernel来完成jupyter的conda环境切换

安装kernel

比如现在我新建了个conda环境
conda create -n th python=3.7
该环境th是用来跑pytorch代码的
切换环境到th
activate th
在th环境下安装ipykernel
(想让jupyter使用该环境就必须在该环境下安装ipykernel)
pip install ipykernel
通过ipykernel就可以安装kernel
python -m ipykernel install --name th
其中th为kernel的名字,可以任意取,不过建议和conda环境名一样方便确认.
在哪个conda环境下执行以上命令,就会生成该环境的kernel

安装jupyterlab

安装jupyterlab时可以切换回默认的环境,这样每次启动不用切换环境
activate base
pip install jupyterlab
运行 jupyterlab
jupyter-lab


jupyterlab

如上th的kernel成功安装后就会显示在右侧,大功告成

补充

查看kernel命令
jupyter-kernelspec list
删除kernel命令
(conda环境删除后,相应的kernel却不会删除,使用kernel会报错,所以删除conda环境后,应一并删除相应kernel)
jupyter kernelspec remove th
th为kernel名

你可能感兴趣的:(win10环境conda安装jupyter-lab和kernel)