John Mahoney

python tips

How to use Jupyter notebook and iPython at the same time

I often find that when I am working in a notebook that am unsure of some small thing like: whether a variable has been defined, the shape of an array, if an operation will broadcast correctly, etc. Using just a notebook, you have to create a new cell, enter the query, execute the cell, and then clean up by deleting the cell. I wanted the immediate gratification of iPython as well as the clean structure of the notebook.

Well now you can have both and in a reasonably slick way.

One option is to execute the following in the notebook:

%qtconsole

This brings up an iPython terminal in a new window that is tied to the same kernel. So it is essentially one working environment.

The other option is, after running

jupyter notebook

and initiating a new notebook, the terminal output will look something like:

[I 21:55:30.378 NotebookApp] Kernel started: cb7ac7b8-1b08-4fe4-b3e3-1a7ead28aed9

You simply copy the first chunk of the kernel address and enter into some other terminal:

ipython console --existing 4604c4c3

So far the two methods seem pretty equivalent.