美文网首页
在Jupyter notebook中切换IPython Kern

在Jupyter notebook中切换IPython Kern

作者: 一筐荚果 | 来源:发表于2017-12-20 13:04 被阅读1026次

在 Jupyter notebook 新建 Notebook 菜单下有 python2、python3可选,且在Kernel --> change Kernel 中可以切换执行的内核.

首先,需要分别在 python2,python3的环境下安装ipykernel:

conda install ipykernel

如果用的是anaconda3版本,那么 Python3环境下的 ipykernel 已经装好了。然后分别建 kernel :

ipython kernel install
ipython3 kernel install

这样在/anaconda3/share/jupyter/kernels/ 目录下有 python2、python3两个文件夹,可以查看kernel.json的内容

{
 "argv": [
  "/anaconda3/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

现在运行jupyter notebook,ipython notebookipython3 notebook就能切换了。第一次切换可能会报错:

错误信息

conda install autopep8之后再打开 Jupyter notebook。尝试切换到python2下:

import numpy
print numpy.__version__

如果你有自己独特的 python 可执行环境,可以尝试:

path/to/python -m ipykernel install <options>

conda create -n py36-test python=3.6
source activate py36-test
python -m ipykernel install --name py36-test
source deactivate

这样下拉菜单里就有py36-test这个 kernel 了.

参考Using both Python 2.x and Python 3.x in IPython Notebook获得更多解释。

一个不太相关的 tips:把文件夹拖进终端就能得到绝对路径,如果是 zsh 直接回车就进入指定目录了!方不方便,快不快捷!其他 shell 没试过,可以试一下。

相关文章

网友评论

      本文标题:在Jupyter notebook中切换IPython Kern

      本文链接:https://www.haomeiwen.com/subject/grfgwxtx.html