Search code examples
ipythonjupyter-notebook

Jupyter notebook - connect to the same kernel session from a command line ipython?


Suppose I've a Jupyter notebook loaded in a browser. Is that possible to somehow run a command line ipython session which connect to the same kernel instance as the one used by the notebook (i.e they can see the same set of variables)? Thanks.


Solution

  • Yes! After starting/loading an IPython notebook, open up a terminal and connect a command line ipython session using the --existing parameter:

    jupyter console --existing
    

    By default, it will connect to the latest started IPython kernel. To select a different kernel to connect to, look in the log of the Jupyter notebook for lines like these:

    [I 09:47:54.462 NotebookApp] Kernel started: 06c9ffae-ae9f-4c22-93c0-4eacf23672b1
    

    To connect to this kernel, do:

    jupyter console --existing 06c9ffae-ae9f-4c22-93c0-4eacf23672b1