今天用jupyternotebook来学习github上的一个项目,发现运行时报ModuleNotFoundError的错。检查了一下发现问题应该处在notebook的kernel上。因为我在电脑上装了不同的python环境,所以想要用特定的包就需要切换python环境。这里通过kernel实现。
增加kernel
第一步:打开cmd,进入想要使用的python环境下。在该环境下利用pip安装ipykernel
。
(python36) C:\Users\mark吐温>pip install ipykernel
第二步:安装完成后,输入jupyter kernelspec list
命令查看当前的kernel。
(python36) C:\Users\mark吐温>jupyter kernelspec list
Available kernels:
python3 d:\anaconda3\envs\python36\share\jupyter\kernels\python3
第三步:同样在该python环境下,输入以下命令创建新的kernel。(注意:‘–name python36’中的python36是你可以指定的kernel名字。)
(python36) C:\Users\mark吐温>python -m ipykernel install --name python36
第四步:查看当前kernel。可以看到已经增加了名为python36的kernel。
(python36) C:\Users\mark吐温>jupyter kernelspec list
Available kernels:
python3 d:\anaconda3\envs\python36\share\jupyter\kernels\python3
python36 C:\ProgramData\jupyter\kernels\python36
第五步:返回jupyter notebook,将kernel切换至python36。问题解决了!
删除kernel
在上述python环境下输入jupyter kernelspec remove python36
命令。yes确认后即可删除相应的kernel。
(python36) C:\Users\mark吐温>jupyter kernelspec remove python36
Kernel specs to remove:
python36 C:\ProgramData\jupyter\kernels\python36
Remove 1 kernel specs [y/N]: y
[RemoveKernelSpec] Removed C:\ProgramData\jupyter\kernels\python36
这时再次查看当前kernel时,就只剩最初的kernel了。
(python36) C:\Users\mark吐温>jupyter kernelspec list
Available kernels:
python3 d:\anaconda3\envs\python36\share\jupyter\kernels\python3