Skip to content Skip to sidebar Skip to footer

Jupyter Notebook With Python 2 And Python3 Kernel

I want to run Python2 as well as Python3 kernel from Jupiter notebook. I am using Anaconda for Python and Jupyter distribution. Lokeshs-MacBook-Air-2:~ lokeshagrawal$ conda --versi

Solution 1:

  1. Make sure you have pip version greater than 9.0
$ python2 -m pip --version
  1. Then do this
$ python2 -m pip install ipykernel OR python2 -m pip install ipykernel --user
$ python2 -m ipykernel install --user
  1. Start or restart Jupyter and you should be done.

This solution is from the ipython docs by the way.

Solution 2:

You can do:

conda create —name py2 python=2.7 anaconda 
conda activate py2(py2) conda install ipykernel -y
(py2) python -m ipykernel install --user --name py2 --display-name "Python 2.7"

This creates an environment called py2 with Python 2.7 and adds it to your kernel with name Python 2.7

If we want to have other versions e.g. Python 3.7 also, we can do the same steps:

conda update conda
conda create —name py3 python=3.7 anaconda 
conda activate py3
(py3) conda install ipykernel -y
(py3) python -m ipykernel install --user --name py3 --display-name "Python 3.7"

Note: you do not have to add 'anaconda' packages. Hope this helps you understand how to add environments to your jupyter kernel.

See: Anaconda Documentation

Post a Comment for "Jupyter Notebook With Python 2 And Python3 Kernel"