Juypter notebook如何导入anaconda中建立的多个python环境?
解决方法1:
1)conda activate my_environment切换到要添加的python环境
2)确认是否安装 ipykernel
pip show ipykernel
pip3 show ipykernel
如果没有ipykernel,则安装:
pip install ipykernel
pip install ipykernel==5.1.0
pip3 install ipykernel
conda install -c conda-forge ipykernel
conda install -c conda-forge ipykernel=5.1.0
3)确认是否安装jupyter notebook
如果已经安装好jupyter notebook,则下面命令可显示版本:
jupyter notebook --version
如果没有,则在服务器上安装jupyter notebook
# 普通安装
conda install jupyter notebook
# 带镜像安装
conda install jupyter notebook https://pypi.tuna.tsinghua.edu.cn/simple
# 指定版本安装
conda install notebook==6.5yy
conda install notebook==6.4.12
4)查看 Jupyter notebook 已有的内核
jupyter kernelspec list
5)为 Jupyter notebook 添加内核
用conda env list展示可用python环境(内核)
python -m ipykernel install --user --name=xxx(要添加的内核名称,即环境名称) --display-name xxx(添加的内核在jupyter notebook中的显示名称)
6)删除 jupyter 内核
jupyter kernelspec remove kernelname(待删除的内核名称)
解决方法2:
见该帖:Conda environments not showing up in Jupyter Notebook.
首先,在前面激活的新环境下安装nb_conda_kernels包:
conda install nb_conda_kernels
然后,打开Notebook,点击New,会出现当前所有安装的虚拟环境以供选择,如下所示。

set-env-in-notebook-choose-kernel.png
如果是已经编辑过的notebook,只需要打开该笔记本,在菜单栏中选择Kernel -> choose kernel -> your env kernel即可。

set-env-in-notebook-change-kernel.png