使用anaconda创建多个虚拟环境后,若是选择在每个环境新安装jupyter notebook,内核版本容易出现与虚拟环境Python版本不一致,本教程旨在解决多环境内核切换问题。
文章目录
1.安装
1.1 base环境安装ipykernel
conda install jupyter ipykernel
1.2 创建新的虚拟环境
以创建名为tensorflow,Python版本为3.7的虚拟环境为例
conda create -n tensorflow python==3.7
创建完成后切换到tensorflow环境
conda activate tensorflow
1.3 在虚拟环境中安装ipykernel
conda install ipykernel
2 配置
–name 环境名称
–display-name 在jupyter notebook显示的别名
python -m ipykernel install --user --name tensorflow --display-name "tensorflow"
3 使用
3.1 启动jupyter
回到base环境中启动jupyter notebook
conda deactivate 或 conda activate base
jupyter notebook
3.2 切换内核
3.3 查看jupyter中的环境内核
jupyter kernelspec list
3.4 删除jupyter中的环境内核
jupyter kernelspec remove tensorflow