我的Jupyter笔记本电脑安装了python 2内核。我不明白为什么。我可能在安装的时候搞砸了。我已经安装了python 3。我怎么能把它加到木星上? 下面是默认的Jupyter使用python3 -m install Jupyter安装并在浏览器中使用Jupyter notebook打开的截图:
当前回答
将多个内核安装到单个虚拟环境(venv)
这些答案中的大多数(如果不是全部的话)假设您乐于在全局范围内安装包。这个答案适合你,如果你:
使用*NIX机器 不喜欢全局安装包 不要使用anaconda <->,你很乐意从命令行运行jupyter服务器 想要知道内核安装“在哪里”。
(注意:这个答案在python3-jupyter安装中添加了一个python2内核,但在概念上很容易交换。)
Prerequisites You're in the dir from which you'll run the jupyter server and save files python2 is installed on your machine python3 is installed on your machine virtualenv is installed on your machine Create a python3 venv and install jupyter Create a fresh python3 venv: python3 -m venv .venv Activate the venv: . .venv/bin/activate Install jupyterlab: pip install jupyterlab. This will create locally all the essential infrastructure for running notebooks. Note: by installing jupyterlab here, you also generate default 'kernel specs' (see below) in $PWD/.venv/share/jupyter/kernels/python3/. If you want to install and run jupyter elsewhere, and only use this venv for organizing all your kernels, then you only need: pip install ipykernel You can now run jupyter lab with jupyter lab (and go to your browser to the url displayed in the console). So far, you'll only see one kernel option called 'Python 3'. (This name is determined by the display_name entry in your kernel.json file.) Add a python2 kernel Quit jupyter (or start another shell in the same dir): ctrl-c Deactivate your python3 venv: deactivate Create a new venv in the same dir for python2: virtualenv -p python2 .venv2 Activate your python2 venv: . .venv2/bin/activate Install the ipykernel module: pip install ipykernel. This will also generate default kernel specs for this python2 venv in .venv2/share/jupyter/kernels/python2 Export these kernel specs to your python3 venv: python -m ipykernel install --prefix=$PWD/.venv. This basically just copies the dir $PWD/.venv2/share/jupyter/kernels/python2 to $PWD/.venv/share/jupyter/kernels/ Switch back to your python3 venv and/or rerun/re-examine your jupyter server: deactivate; . .venv/bin/activate; jupyter lab. If all went well, you'll see a Python 2 option in your list of kernels. You can test that they're running real python2/python3 interpreters by their handling of a simple print 'Hellow world' vs print('Hellow world') command. Note: you don't need to create a separate venv for python2 if you're happy to install ipykernel and reference the python2-kernel specs from a global space, but I prefer having all of my dependencies in one local dir
博士TL;
Optionally install an R kernel. This is instructive to develop a sense of what a kernel 'is'. From the same dir, install the R IRkernel package: R -e "install.packages('IRkernel',repos='https://cran.mtu.edu/')". (This will install to your standard R-packages location; for home-brewed-installed R on a Mac, this will look like /usr/local/Cellar/r/3.5.2_2/lib/R/library/IRkernel.) The IRkernel package comes with a function to export its kernel specs, so run: R -e "IRkernel::installspec(prefix=paste(getwd(),'/.venv',sep=''))". If you now look in $PWD/.venv/share/jupyter/kernels/ you'll find an ir directory with kernel.json file that looks something like this:
{
"argv": ["/usr/local/Cellar/r/3.5.2_2/lib/R/bin/R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
"display_name": "R",
"language": "R"
}
总之,内核只是从内核调用特定于语言的可执行文件。Json文件,jupyter在…/share/jupyter/kernels目录和列表在本例中,调用R来运行IRkernel::main()函数,该函数将向Jupiter服务器来回发送消息。类似地,python2内核只是使用ipykernel_launcher模块调用python2解释器,如.venv/share/jupyter/kernels/python2/kernel中所示。json等。
如果您想一下子运行所有这些指令,这里有一个脚本。
其他回答
我有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。
用于当前的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
我用以下命令成功地在macOS El Capitan (ipython版本:4.1.0)上安装了python3内核。
python3 -m pip install ipykernel
python3 -m ipykernel install --user
你可以在jupyter kernelspec列表中看到所有已安装的内核。
更多信息可以在这里找到
将多个内核安装到单个虚拟环境(venv)
这些答案中的大多数(如果不是全部的话)假设您乐于在全局范围内安装包。这个答案适合你,如果你:
使用*NIX机器 不喜欢全局安装包 不要使用anaconda <->,你很乐意从命令行运行jupyter服务器 想要知道内核安装“在哪里”。
(注意:这个答案在python3-jupyter安装中添加了一个python2内核,但在概念上很容易交换。)
Prerequisites You're in the dir from which you'll run the jupyter server and save files python2 is installed on your machine python3 is installed on your machine virtualenv is installed on your machine Create a python3 venv and install jupyter Create a fresh python3 venv: python3 -m venv .venv Activate the venv: . .venv/bin/activate Install jupyterlab: pip install jupyterlab. This will create locally all the essential infrastructure for running notebooks. Note: by installing jupyterlab here, you also generate default 'kernel specs' (see below) in $PWD/.venv/share/jupyter/kernels/python3/. If you want to install and run jupyter elsewhere, and only use this venv for organizing all your kernels, then you only need: pip install ipykernel You can now run jupyter lab with jupyter lab (and go to your browser to the url displayed in the console). So far, you'll only see one kernel option called 'Python 3'. (This name is determined by the display_name entry in your kernel.json file.) Add a python2 kernel Quit jupyter (or start another shell in the same dir): ctrl-c Deactivate your python3 venv: deactivate Create a new venv in the same dir for python2: virtualenv -p python2 .venv2 Activate your python2 venv: . .venv2/bin/activate Install the ipykernel module: pip install ipykernel. This will also generate default kernel specs for this python2 venv in .venv2/share/jupyter/kernels/python2 Export these kernel specs to your python3 venv: python -m ipykernel install --prefix=$PWD/.venv. This basically just copies the dir $PWD/.venv2/share/jupyter/kernels/python2 to $PWD/.venv/share/jupyter/kernels/ Switch back to your python3 venv and/or rerun/re-examine your jupyter server: deactivate; . .venv/bin/activate; jupyter lab. If all went well, you'll see a Python 2 option in your list of kernels. You can test that they're running real python2/python3 interpreters by their handling of a simple print 'Hellow world' vs print('Hellow world') command. Note: you don't need to create a separate venv for python2 if you're happy to install ipykernel and reference the python2-kernel specs from a global space, but I prefer having all of my dependencies in one local dir
博士TL;
Optionally install an R kernel. This is instructive to develop a sense of what a kernel 'is'. From the same dir, install the R IRkernel package: R -e "install.packages('IRkernel',repos='https://cran.mtu.edu/')". (This will install to your standard R-packages location; for home-brewed-installed R on a Mac, this will look like /usr/local/Cellar/r/3.5.2_2/lib/R/library/IRkernel.) The IRkernel package comes with a function to export its kernel specs, so run: R -e "IRkernel::installspec(prefix=paste(getwd(),'/.venv',sep=''))". If you now look in $PWD/.venv/share/jupyter/kernels/ you'll find an ir directory with kernel.json file that looks something like this:
{
"argv": ["/usr/local/Cellar/r/3.5.2_2/lib/R/bin/R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
"display_name": "R",
"language": "R"
}
总之,内核只是从内核调用特定于语言的可执行文件。Json文件,jupyter在…/share/jupyter/kernels目录和列表在本例中,调用R来运行IRkernel::main()函数,该函数将向Jupiter服务器来回发送消息。类似地,python2内核只是使用ipykernel_launcher模块调用python2解释器,如.venv/share/jupyter/kernels/python2/kernel中所示。json等。
如果您想一下子运行所有这些指令,这里有一个脚本。
在Ubuntu 14.04上,我不得不使用之前答案的组合。
首先,安装pip3 安装python-pip3
然后用pip3安装jupyter Pip3安装jupyter
然后使用ipython3安装内核 Ipython3内核安装
推荐文章
- Python和IPython的区别是什么?
- 如何从终端运行。ipynb Jupyter Notebook ?
- 移除jupyter笔记本上的内核
- 如何使用列的格式字符串显示浮动的熊猫数据帧?
- 使用Python 2。3. Python。IPython Notebook中的x
- 如何加载/编辑/运行/保存文本文件(.py)到IPython笔记本细胞?
- 在安装pip后,“jupyter:命令未找到”
- 在IPython中自动重载模块
- 如何防止谷歌Colab断开连接?
- 熊猫:设定号。Max行数
- 如何在Jupyter Notebook中显示文件中的图像?
- 熊猫操作期间的进度指标
- 修改IPython/Jupyter笔记本工作目录
- 在ipython笔记本中测量单元格执行时间的简单方法
- 插入图像到IPython笔记本markdown