我的Jupyter笔记本电脑安装了python 2内核。我不明白为什么。我可能在安装的时候搞砸了。我已经安装了python 3。我怎么能把它加到木星上? 下面是默认的Jupyter使用python3 -m install Jupyter安装并在浏览器中使用Jupyter notebook打开的截图:


当前回答

这对我在Ubuntu 16.04上是有效的:

python2 -m pip install ipykernel
python2 -m ipykernel install --user

python3 -m pip install ipykernel
python3 -m ipykernel install --user

参考文档: Python 2和3的内核。安装IPython内核- IPython Docs。

其他回答

以下命令适用于macOS Sierra(10.12.3)

python3 -m pip install ipykernel
python3 -m ipykernel install --user

用 Jupyter内核规格列表 可用内核: python3 /用户/ admin /图书馆/ Jupyter /内核/ python3 python2 / anaconda2 /分享/ jupyter /内核/ python2

我很确定你要做的就是逃跑

Pip3安装jupyter

我有Python 2.7,并希望能够在Jupyter内部切换到Python 3。

这些步骤在Windows Anaconda命令提示符上为我工作:

conda update conda
conda create -n py33 python=3.3 anaconda
activate py33
ipython kernelspec install-self
deactivate

现在,在使用Python2.7的常用命令打开ipython notebook之后,在创建新notebook时也可以使用Python3.3。

如果你使用的是anaconda发行版,这对我来说是有效的(在macintosh上):

$ conda create -n py3k python=3 anaconda

$ source activate py3k

$ ipython kernelspec install-self

最后一个命令需要注意:

(py3k)Monas-MacBook-Pro:cs799 mona$ ipython kernelspec install-self
[TerminalIPythonApp] WARNING | Subcommand `ipython kernelspec` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter kernelspec` in the future
[InstallNativeKernelSpec] WARNING | `jupyter kernelspec install-self` is DEPRECATED as of 4.0. You probably want `ipython kernel install` to install the IPython kernelspec.
[InstallNativeKernelSpec] Installed kernelspec python3 in /usr/local/share/jupyter/kernels/python3
(py3k)Monas-MacBook-Pro:cs799 mona$ ipython kernel install 
Installed kernelspec python3 in /usr/local/share/jupyter/kernels/python3

按照上述步骤在OSX Yosemite中进行测试,并输入jupter notebook并在浏览器中创建一个新的notebook,您将看到以下截图:

除了Python2之外,我还设法安装了Python3内核。我是这样做的:

在木星上打开一个新的笔记本 复制并运行这里的两个单元格:Enable-Python-3-kernel

最新的工作链接可以在这里找到。

实际代码为:

! 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"
 }
}