8

I have installed on Debian Jessie:

Python2.7

Python3.5

I have also installed Jupyter via pip2 and pip3

However when I launch jupyter-notebook I can only use python3 as kernel! How can I switch to pyhton2.7 when using Jupyter?

pneumatics
  • 2,836
  • 1
  • 27
  • 27
S12000
  • 3,345
  • 12
  • 35
  • 51
  • 1
    Possible duplicate of [Using both Python 2.x and Python 3.x in IPython Notebook](http://stackoverflow.com/questions/30492623/using-both-python-2-x-and-python-3-x-in-ipython-notebook) – pneumatics Dec 21 '15 at 22:11
  • the best solution shows how to solve the issue with anaconda. I want to avoid anaconda. – S12000 Dec 22 '15 at 00:45
  • I think you can adapt [the accepted answer](http://stackoverflow.com/a/30493051/347567), though I can now see this is not a true duplicate since you're on Debian instead of OS X. – pneumatics Dec 22 '15 at 00:53

2 Answers2

7

I tried this with a fresh Debian 8.5 machine on Digital Ocean.

As root, install pip and jupyter from apt, and the development packages, too.

apt-get install python-pip python-dev python3-pip python3-dev libzmq3
pip3 install jupyter

Add the kernel for Python2 using the ipykernel module. The Python3 kernel is installed, already.

pip install ipykernel
python2 -m ipykernel install

When you run jupyter notebook, you should have both Python 2 and Python 3 listed as available kernels. Notice that the Tornado notebook server is serving HTTP on port 8888, which isn't opened by default on many machines. Here is a script that will run Jupyter for you, opening and closing port 8888 and running on a public IP.

Jupyter web interface showing both kernels available for new notebooks

pneumatics
  • 2,836
  • 1
  • 27
  • 27
  • hello thanks a lot for the answer. I have tired on my machine I get no error but still dont get both python 2 and 3 (only 3).I will try to investigate further. – S12000 Dec 23 '15 at 02:02
  • the output of `ipython kernelspec install-self` should confirm that a kernel was installed, and it will say which version. You have to `sudo` the kernelspec command, too. – pneumatics Dec 23 '15 at 16:18
  • In recent versions of ipython, the commands should be `ipython kernel install` and `ipython3 kernel install` – Abderrahim Kitouni Jul 11 '16 at 11:19
  • @AbderrahimKitouni thanks, I updated the instructions based on the current docs. – pneumatics Jul 11 '16 at 17:48
0

I can't test this right now, but jupyter-notebook is probably looking at your $PATH variable to find a python. When you type python --version, is it python2?

If it isn't, you can choose which python to use by changing your $PATH variable so python2 is before python3.

Community
  • 1
  • 1
Ben
  • 5,952
  • 4
  • 33
  • 44
  • i tired : python --version the output is Python 2.7.9 – S12000 Dec 21 '15 at 21:35
  • This answer won't help you then. Maybe some links will: http://stackoverflow.com/questions/28831854/how-do-i-add-python3-kernel-to-jupyter-ipython and http://stackoverflow.com/questions/30492623/using-both-python-2-x-and-python-3-x-in-ipython-notebook – Ben Dec 21 '15 at 21:40
  • Also look at trying [Anaconda python](https://www.continuum.io/downloads) to drastically simplify installing packages like this. Conda environments might also be the answer to your kernel problem here. – Ben Dec 21 '15 at 21:46
  • Hi, I would like to avoid anaconda. The reason is that I run other scripts other packages (computer vision packages). For the moment I use anaconda on a VM... – S12000 Dec 22 '15 at 00:47