系统:
Windows 10
背景:
电脑卸载又重新安装过Anaconda,因为重新安装之后jupyter notebook一直显示错误“内核死亡”。怀疑是重新安装的问题,又把Anaconda卸载了。发现jupyter notebook仍然保留了Anaconda建立的虚拟环境。试图使用cmd打开jupyter notebook找到问题所在。使用了pipenv的虚拟环境进行尝试。
解决:
1、win + R 打开电脑cmd,进入pipenv建立的虚拟环境
2、输入 pipenv shell 启动已经装好的pipenv虚拟环境
pipenv shell
3、使用 pipenv install 安装numpy、pandas、matplotlib、ipython、jupyter等包,笔者提前全都安装了,并不太清楚这里面哪些包对打开jupyter notebook起了作用,估计是ipython和jupyter。
4、cmd输入 jupyter notebook 打开jupyter notebook
jupyter notebook
打开的jupyter notebook默认位置为虚拟环境的目录,笔者此处是 E:\hello\PyNumbers
5、打开 .ipynb 文件,发现内核仍然死亡,且内核保留了卸载前 Anaconda 创建的虚拟环境(注:卸载 Anaconda 时进行了 clean 操作,但 jupyter notebook 仍然保留了)
6、在 cmd 输入 jupyter kernelspec list 查找内核
jupyter kernelspec list
7、打开你想要使用的内核的位置,比如 mindspor,可以发现其中有 kernel.json 文件
8、打开 kernel.json 文件,发现其中所指的 python 路径位置已卸载,没有使用
9、将路径位置修改为你正在使用的 python 位置,如笔者正在使用 pipenv 虚拟环境下的 python ,则找到虚拟环境路径下的 python.exe,同时注意.json文件不能出现注释。
10、再次回到 jupyter notebook,则内核可以使用,kernel error 消失。
提醒:
此时 jupyter notebook 使用的是 pipenv 虚拟环境中的包,不像Anaconda那样全都提前下载,需要自行下载代码所需要的包。