我的Jupyter笔记本电脑安装了python 2内核。我不明白为什么。我可能在安装的时候搞砸了。我已经安装了python 3。我怎么能把它加到木星上? 下面是默认的Jupyter使用python3 -m install Jupyter安装并在浏览器中使用Jupyter notebook打开的截图:
当前回答
确保已经安装了ipykernel,并使用ipython kernel install将kernelspec放到python2的正确位置。然后为Python3安装ipython3内核。现在,无论您使用的是jupyter notebook、ipython notebook还是ipython3 notebook(后两种已弃用),您都应该能够在这两种内核之间进行选择。
注意,如果你想安装一个特定的Python可执行文件,你可以使用以下技巧:
path/to/python -m ipykernel install <options>
当使用环境(venv,conda,…)和<选项>让你命名你的内核时,这是有效的(参见——help)。所以你可以
conda create -n py36-test python=3.6
source activate py36-test
python -m ipykernel install --name py36-test
source deactivate
现在,在下拉菜单中可以看到名为py36-test的内核和其他内核。
参见使用Python 2。3. Python。IPython Notebook中的最新信息。
其他回答
我很确定你要做的就是逃跑
Pip3安装jupyter
当你使用conda管理你的python envs时,遵循以下两个步骤:
激活py3(在Windows上或在Linux上激活py3) Conda install notebook ipykernel或者直接使用Conda install jupyter
对于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
在Ubuntu 14.04上,我不得不使用之前答案的组合。
首先,安装pip3 安装python-pip3
然后用pip3安装jupyter Pip3安装jupyter
然后使用ipython3安装内核 Ipython3内核安装
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).
推荐文章
- 当试图运行Python脚本时,“ImportError:没有命名模块”
- 如何阅读一个。xlsx文件使用熊猫库在iPython?
- 检查pandas数据框架索引中是否存在值
- Ipython笔记本清除单元格输出代码
- tqdm在Jupyter笔记本重复打印新的进度条
- 折叠单元在jupyter笔记本
- 如何知道哪个Python在Jupyter笔记本上运行?
- 使用Python 3在Jupyter Notebook中使用相对导入从位于另一个目录中的模块导入本地函数
- 如何嵌入HTML到IPython输出?
- Python和IPython的区别是什么?
- 如何从终端运行。ipynb Jupyter Notebook ?
- 移除jupyter笔记本上的内核
- 如何使用列的格式字符串显示浮动的熊猫数据帧?
- 使用Python 2。3. Python。IPython Notebook中的x
- 如何加载/编辑/运行/保存文本文件(.py)到IPython笔记本细胞?