在jupyter中使用虚拟环境

安装完Anaconda利用conda创建了虚拟环境,但是启动jupyter notebook之后却找不到虚拟环境。

实际上是由于在虚拟环境下缺少kernel.json文件,解决方法如下:

首先安装ipykernel

conda install ipykernel

在虚拟环境下创建kernel文件:

conda install -n 环境名称 ipykernel

激活conda环境:

source activate 环境名称

将环境写入notebook的kernel中

python -m ipykernel install --user --name 环境名称 --display-name "Python (环境名称)"

打开notebook服务器:

jupyter notebook

浏览器打开对应地址,新建python,就会有对应的环境提示了

如果经常需要用jupyter notebook,那么最好在创建虚拟环境的时候便安装好ipykernel,命令:

conda create -n 环境名称 python=3.5 ipykernel

删除kernel环境:

jupyter kernelspec remove 环境名称

猜你喜欢

转载自blog.csdn.net/qq_32963855/article/details/112769963