Reputation: 5127
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 --version
conda 4.5.12
Lokeshs-MacBook-Air-2:~ lokeshagrawal$ which python
/anaconda3/bin/python
Lokeshs-MacBook-Air-2:~ lokeshagrawal$ which jupyter notebook
/anaconda3/bin/jupyter
[![Lokeshs-MacBook-Air-2:~ lokeshagrawal$ python --version
Python 3.7.2
As you can see in the image below, I only have an option to start Python3 kernel from Jupyter. How can I have Python2 and Python3 both?
Upvotes: 10
Views: 9024
Reputation: 15568
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.
Upvotes: 2
Reputation: 655
$ python2 -m pip --version
$ python2 -m pip install ipykernel OR python2 -m pip install ipykernel --user
$ python2 -m ipykernel install --user
This solution is from the ipython docs by the way.
Upvotes: 5