How do I add python3 kernel to jupyter (IPython)
Solution 1
This worked for me on Ubuntu 16.04:
python2 -m pip install ipykernel
python2 -m ipykernel install --user
python3 -m pip install ipykernel
python3 -m ipykernel install --user
Reference to the documentation:
Kernels for Python 2 and 3. Installing the IPython kernel - IPython Docs.
Solution 2
Make sure you have ipykernel
installed and use ipython kernel install
to drop the kernelspec in the right location for python2. Then ipython3 kernel install
for Python3. Now you should be able to chose between the 2 kernels regardless of whether you use jupyter notebook
, ipython notebook
or ipython3 notebook
(the later two are deprecated).
Note that if you want to install for a specific Python executable you can use the following trick:
path/to/python -m ipykernel install <options>
This works when using environments (venv,conda,...) and the <options>
let you name your kernel (see --help
). So you can do
conda create -n py36-test python=3.6
source activate py36-test
python -m ipykernel install --name py36-test
source deactivate
And now you get a kernel named py36-test
in your dropdown menus, along the other ones.
See Using both Python 2.x and Python 3.x in IPython Notebook which has more recent information.
Solution 3
- Got ipython notebook with Python2 (on Windows7)
- upgrade to Jupyter with
pip install -U jupyter
- install Python3
- install Jupyter again using
pip3 install jupyter
- install Python3 kernel using
ipython3 kernelspec install-self
- I finally got 2 working kernels.
Solution 4
for recent versions of jupyter/ipython: use jupyter kernelspec
Full doc: https://ipython.readthedocs.io/en/latest/install/kernel_install.html
list current kernels
$ jupyter kernelspec list
Available kernels:
python2 .../Jupyter/kernels/python2
python3 .../Jupyter/kernels/python3
In my case, the python3 kernel setup was broken because the py3.5 linked was no longer there, replaced by a py3.6
add/remove kernels
Remove:
$ jupyter kernelspec uninstall python3
Add a new one: Using the Python you wish to add and pointing to the python which runs your jupiter:
$ /path/to/kernel/env/bin/python -m ipykernel install --prefix=/path/to/jupyter/env --name 'python-my-env'
See more examples in https://ipython.readthedocs.io/en/6.5.0/install/kernel_install.html#kernels-for-different-environments
List again:
$ jupyter kernelspec list
Available kernels:
python3 /usr/local/lib/python3.6/site-packages/ipykernel/resources
python2 /Users/stefano/Library/Jupyter/kernels/python2
Doc: https://jupyter-client.readthedocs.io/en/latest/kernels.html#kernelspecs
Details
Kernels available are listed under the kernels
folder in Jupyter DATA DIRECTORY (see http://jupyter.readthedocs.io/en/latest/projects/jupyter-directories.html for details).
For instance on macosx that would be /Users/YOURUSERNAME/Library/Jupyter/kernels/
the kernel is simply described by a kernel.json
file, eg. for /Users/me/Library/Jupyter/kernels/python3/kernel.json
{
"argv": [
"/usr/local/opt/python3/bin/python3.5",
"-m",
"ipykernel",
"-f",
"{connection_file}"
],
"language": "python",
"display_name": "Python 3"
}
Rather then manipulating that by hand, you can use the kernelspec
command (as above). It was previously available through ipython now through 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`
Kernels for other languages
By the way, not strictly related to this question but there's a lot of other kernels available... https://github.com/jupyter/jupyter/wiki/Jupyter-kernels
Solution 5
If you are using the anaconda distribution, this worked for me (on a macintosh):
$ conda create -n py3k python=3 anaconda
$ source activate py3k
$ ipython kernelspec install-self
Just a note for the last command:
(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
As tested in OSX Yosemite with the above steps and entering jupter notebook
and creating a new notebook in the browser you will see the following screenshot:
quickbug
I am a researcher in soil science. More specifically in erosion science applied to arable land in the South. I never heard about that! Is it worth your time (and the tax payers' money) ? Yes it is. Many great civilisations have collapsed by various proximate consequences of the same ultimate cause : the gradual depletion of their arable land. Our civilisation is possibly (certainly?) doomed to the same fate. The end of the Internet because of soil degradation? Are you kidding me? No I am not. - Less arable land makes less internal food production - less food produced internally makes more people eating imported food. - buying imported food needs money - money in poor unindustrialized countries is ultimately provided by the state. - Overwhelmed states must cut the other expenses, especialy education, police and justice. - impoverished states, no police to enforce the laws, no judiciary to punish traficking and corruption, hungry peoples disparing for the future of their children, and what ? governments collapse and their countries implode. - Imploded countries are paradises for guns- and drug-trafickers, and terrorists camps. - Healthy countries cannot sustain on the long term with the law of the jungle at their boundaries. Et voila. Madagascar and Haiti are prime examples of the final stage of this deadly downward spiral that soil degradation triggered decades ago. Mali and Central African Republic have just slipped down the slippery slope. People must eat. At any cost, even by distroying their homeland or bringing their country near collapse. This leaves very little room for reversing the spiral, and great hope in erosion science for its (expected) contribution to a more sustainable agriculture. Thanks for reading. Feedbacks are welcomed at olivier dot planchon at gmail dot com.
Updated on March 05, 2021Comments
-
quickbug about 3 years
My
Jupyter
notebooks installed withpython 2
kernel. I do not understand why. I might have messed something up when I did the install. I already havepython 3
installed. How can I add it toJupyter
? Here's a screenshot of what the defaultJupyter
insalled withpython3 -m install jupyter
and opened in the browser withjupyter notebook
looks like: