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


当前回答

如果你使用的是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,您将看到以下截图:

其他回答

在ElementaryOS Freya(基于Ubuntu 14.04)上,其他答案都没有立即对我起作用;我得到了

[TerminalIPythonApp]警告|文件不存在:'kernelspec'

quickbug在Matt的回答中描述的错误。我首先要做的是:

Sudo apt-get安装pip3

安装ipython[所有]

这时你就可以运行Matt建议的命令了;即:ipython kernelspec install-self和ipython3 kernelspec install-self

现在,当我启动ipython notebook,然后打开一个notebook时,我能够从kernel菜单中选择Python 3内核。

我有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。

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

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

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

打开终端(或CMD为窗口),然后执行以下命令: (在窗口中,在第二行中删除“source”。)

conda create -n py35 python=3.5
source activate py35
conda install notebook ipykernel
ipython kernel install --user --name=python3.5

我尝试了一些方法,但它不工作,然后我发现这个方法。 这对我很管用。希望能有所帮助。

对于jupyter/ipython的最新版本:使用jupyter kernelspec

完整文档:https://ipython.readthedocs.io/en/latest/install/kernel_install.html

列出当前内核

$ jupyter kernelspec list
Available kernels:
  python2    .../Jupyter/kernels/python2
  python3    .../Jupyter/kernels/python3

在我的例子中,python3内核设置被破坏了,因为py3.5链接不再存在,取而代之的是py3.6

添加/删除内核

删除:

$ jupyter kernelspec uninstall python3

添加一个新的: 使用你想要添加的Python并指向运行jupiter的Python:

$ /path/to/kernel/env/bin/python -m ipykernel install --prefix=/path/to/jupyter/env --name 'python-my-env'

更多例子见https://ipython.readthedocs.io/en/6.5.0/install/kernel_install.html#kernels-for-different-environments

列表:

$ jupyter kernelspec list
Available kernels:
  python3    /usr/local/lib/python3.6/site-packages/ipykernel/resources
  python2    /Users/stefano/Library/Jupyter/kernels/python2

道格:https://jupyter-client.readthedocs.io/en/latest/kernels.html kernelspecs

细节

可用的内核列在Jupyter DATA DIRECTORY的Kernels文件夹下(详情请参阅http://jupyter.readthedocs.io/en/latest/projects/jupyter-directories.html)。

例如,在macosx上,应该是/Users/YOURUSERNAME/Library/Jupyter/kernels/

内核被简单地描述为内核。Json文件,例如。/用户/我/图书馆/ Jupyter /内核/ python3 / kernel.json

{
 "argv": [
  "/usr/local/opt/python3/bin/python3.5",
  "-m",
  "ipykernel",
  "-f",
  "{connection_file}"
 ],
 "language": "python",
 "display_name": "Python 3"
}

您可以使用kernelspec命令(如上所述),而不是手动操作。以前可以通过ipython使用,现在可以通过jupyter (http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernels-for-different-environments - https://jupyter-client.readthedocs.io/en/latest/kernels.html#kernelspecs)使用。

$ jupyter kernelspec help
Manage Jupyter kernel specifications.

Subcommands
-----------

Subcommands are launched as `jupyter kernelspec cmd [args]`. For information on
using subcommand 'cmd', do: `jupyter kernelspec cmd -h`.

list
    List installed kernel specifications.
install
    Install a kernel specification directory.
uninstall
    Alias for remove
remove
    Remove one or more Jupyter kernelspecs by name.
install-self
    [DEPRECATED] Install the IPython kernel spec directory for this Python.

To see all available configurables, use `--help-all`

其他语言的内核

顺便说一下,与这个问题没有严格联系,但有很多其他可用的内核…https://github.com/jupyter/jupyter/wiki/Jupyter-kernels