Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change IPython 3 for Python 3 kernel to python2 for the cluster too

I have IPython 3 installed for Python 3 in order to work with Jupyterhub.

Now I'm able to use notebooks with a Python2 kernel, because I created /usr/local/share/jupyter/kernels/python2/kernel.json

with:

{
 "argv": ["python2", "-m", "IPython.kernel",
          "-f", "{connection_file}"],
 "display_name": "Python 2",
 "language": "python2"
}

Now I would also like to use IPython.parallel, but when I start a cluster it will automatically start engines in Python 3, how can I change this to Python 2?

like image 819
johnbaltis Avatar asked Apr 21 '15 13:04

johnbaltis


People also ask

How do you change Jupyter kernel from Python 3 to Python 2?

If your Jupyter web server is running on Python 3, you can run the command python2 -m pip install ipykernel to install a Python 2 kernel.

How do I change my Jupyter kernel?

To change the kernel version in Jupyter Python Notebooks follow the steps below : Open the Python Notebook and click on " Kernel " from the menu bar located on top of the python notebook. Click on " Change kernel " from the drop down box that appears and chose the version that is required.

What does Python 3 Ipykernel mean?

The IPython kernel is the Python execution backend for Jupyter. The Jupyter Notebook and other frontends automatically ensure that the IPython kernel is available. However, if you want to use a kernel with a different version of Python, or in a virtualenv or conda environment, you'll need to install that manually.


1 Answers

I solved the issue by

sudo mkdir /etc/ipython/

sudo nano /etc/ipython/ipython_config.py

add these lines:

    c = get_config()

    c.LocalControllerLauncher.controller_cmd = ['/usr/bin/python2', '-m', 'IPython.parallel.controller']
    c.LocalEngineLauncher.engine_cmd = ['/usr/bin/python2', '-m', 'IPython.parallel.engine']
    c.LocalEngineSetLauncher.engine_cmd = ['/usr/bin/python2', '-m', 'IPython.parallel.engine']

And now the engines should start with python2

EDIT for Jupyter 1.0 or IPython 4.0: Change to

c = get_config()

c.LocalControllerLauncher.controller_cmd = ['/usr/bin/python2', '-m', 'ipyparallel.controller']
c.LocalEngineLauncher.engine_cmd = ['/usr/bin/python2', '-m', 'ipyparallel.engine']
c.LocalEngineSetLauncher.engine_cmd = ['/usr/bin/python2', '-m', 'ipyparallel.engine']

and to get the cluster tab back: sudo mkdir /etc/jupyter/

sudo nano /etc/jupyter/jupyter_notebook_config.py

Add this:

c.NotebookApp.server_extensions.append('ipyparallel.nbextension')
like image 68
johnbaltis Avatar answered Sep 22 '22 11:09

johnbaltis