jupyter中添加conda环境(搬运自知乎)

作者:Alex
链接:https://zhuanlan.zhihu.com/p/568557470
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
 

1. 在anaconda中建立环境

conda create --name seaborn python=3.8 -y
conda activate seaborn

2. 将不同的conda环境,加入到jupyter中,共有3种不同的方法:

2.1 将全部conda环境加入到jupyter中

  • 打开base环境,安装nb_conda_kernels:
conda install nb_conda_kernels
  • 在所有需要显示在jupyter的环境中,安装ipykernel(为了使conda和nb_conda_kernels识别到该环境)
conda activate seaborn
conda install ipykernel
  • 重启jupyter,确认全部环境(已经安装了ipykernel的全部环境),全部显示

2.2 将单个conda环境加入到jupyter中(最常使用方式)

#激活你的环境(我的环境叫seaborn)
conda actaivate seaborn

#安装ipykernel(为了使jupyter识别)
conda install ipykernel

#使该环境在jupyter中显示
python -m ipykernel install --user --name 环境名称 --display-name "jupyter中显示名称"

# 查看当前的所有kernel
jupyter kernelspec list

# 删除jupyter notebook的kernel
jupyter kernelspec remove kernelname

2.3 直接从cmd启动环境,不加入jupyter中

(base)$ conda activate new-env
(new_env)$ conda install jupyter
(new_env)$ jupyter notebook

import os
print (os.environ['CONDA_DEFAULT_ENV'])

ref: https://towardsdatascience.com/

你可能感兴趣的:(conda,jupyter,python)