我的 "Jupyter "笔记本安装在 "python 2 "内核上。我不明白为什么。我可能在安装时弄错了什么。我已经安装了 "python 3"。我怎样才能把它添加到 "Jupyter "中?
下面是用python3 -m install jupyter
安装的默认Jupyter
的截图,用jupyter notebook
在浏览器中打开时的样子。
![在此输入图片描述][1] 。
确保你已经安装了ipykernel
,并使用ipython kernel install
将kernelspec放到python2的正确位置。 然后ipython3 kernel install
用于Python3。现在你应该能够在这两个内核之间进行选择,无论你是使用jupyter notebook
、ipython notebook
还是ipython3 notebook
(后两者已被废弃)。
注意,如果你想为一个特定的Python可执行文件进行安装,你可以使用下面的技巧。
path/to/python -m ipykernel install <options>
这在使用环境(venv,conda,...)和<options>
让你命名你的内核时有效(见--help
)。所以你可以做
conda create -n py36-test python=3.6
source activate py36-test
python -m ipykernel install --name py36-test
source deactivate
现在你在你的下拉菜单中得到一个名为py36-test
的内核,与其他内核一起。
见https://stackoverflow.com/questions/30492623/using-both-python-2-x-and-python-3-x-in-ipython-notebook,其中有更多的最新信息。
我设法在Python2之外安装了一个Python3内核。 下面是我的方法。
最新的工作链接可以在这里找到。
实际的代码是。
! mkdir -p ~/.ipython/kernels/python3
%%file ~/.ipython/kernels/python3/kernel.json
{
"display_name": "IPython (Python 3)",
"language": "python",
"argv": [
"python3",
"-c", "from IPython.kernel.zmq.kernelapp import main; main()",
"-f", "{connection_file}"
],
"codemirror_mode": {
"version": 2,
"name": "ipython"
}
}