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


当前回答

用于当前的Python启动器

如果您安装了Py3,但默认为py2

py -3 -m pip install ipykernel
py -3 -m ipykernel install --user

如果您安装了Py2,但默认为py3

py -2 -m pip install ipykernel
py -2 -m ipykernel install --user

其他回答

添加内核意味着你想要使用Jupyter Notebook和列表中没有显示的python版本。

简单的方法-使用所需的python版本启动笔记本,假设我安装了python3.7,然后从终端(cmd)使用以下命令来运行笔记本:

python3.7 -m notebook

有时它会使用别名py, py3.7, python来代替python3.7。

如果你使用的是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内核。

这个回答解释了如何使用Poetry依赖管理创建Python 3、Jupyter 1和ipykernel 5工作流。诗歌使创建一个虚拟环境的Jupyter笔记本很容易。我强烈建议不要运行python3命令。安装全局依赖项的Python工作流程会让你陷入依赖项地狱。

以下是对干净、可靠的Poetry工作流程的总结:

安装依赖诗词添加熊猫jupyter ipykernel 在虚拟环境中用诗壳打开一个壳 打开Jupyter notebook,访问与Jupyter notebook相关的所有虚拟环境

还有干净的Conda工作流。注意这个帖子里的很多答案——它们会让你走上一条会给你带来很多痛苦和折磨的道路。

Here's a Windows/non command line method I found, which worked for me: Find the folder where the kernel files are stored (on my machine - C:\ProgramData\jupyter\kernels - note that ProgramData is a hidden folder), create a copy of the existing kernel's folder, change the name and edit the json file within to point to the new kernel's directory. In this json you can also edit the kernel name that is displayed in ipython (e.g. instead of just python 2 you can specify 2.7.9 if you need to further distinguish for some reason).