Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython notebook: How to connect to existing kernel?

I am able to connect two ipython console session to one kernel by:

$ ipython console
In [1]: %connect_info  
{
   ... Content of JSON with info for connecting ...
}

Paste the above JSON into a file, and connect with:
    $> ipython <app> --existing <file>
or, if you are local, you can connect with just:
    $> ipython <app> --existing kernel-43204.json
or even just:
    $> ipython <app> --existing
    if this is the most recent IPython session you have started.

And accordingly I can substitute the <app> by console again

$ ipython console --existing kernel-43204.json

However, I want to share my kernel with ipython notebook so I can visualize my data. I tried and failed with:

$ ipython notebook --existing kernel-43204.json
[C 13:35:01.025 NotebookApp] Unrecognized flag: '--existing'

Any suggestion how I can work and switch between ipython console and ipython notebook?

like image 878
Oplatek Avatar asked Jul 13 '15 11:07

Oplatek


People also ask

How do I change the kernel in Jupyter Notebook?

To select the kernel in a CoCalc Jupyter notebook, click the “Kernel” button (usually in the middle toolbar, depending on your configuration). In the menu that opens, scroll down past interrupt and restart commands to see the choices for available kernels.

Can you use multiple kernels within the same Jupyter Notebook?

SoS Notebook is an extension to Jupyter Notebook that allows the use of multiple kernels in one notebook. More importantly, it allows the exchange of data among subkernels so that you can, for example, preprocess data using Bash, analyze the processed data in Python, and plot the results in R.


2 Answers

There is no UI, nor API to do that with the notebook, there is an assumption for code simplicity that the notebook is the one that own and start the kernel. You will have to write your own KernelManager subclass and configure IPython to use it (+ write a bit of UI code, if you want it easy to use), for you to be able to select an already existing kernel.

like image 118
Matt Avatar answered Sep 20 '22 08:09

Matt


Here’s the example of custom kernel manager that allows Jupyter notebook to kernel created externally.

https://github.com/ebanner/extipy

It’s hacky solution at best.

Jupyter folks can hopefully create such custome kernel class and include it in package and enable it via simple —existing switch. I don’t see any reason why they can’t do that.

like image 31
Shital Shah Avatar answered Sep 20 '22 08:09

Shital Shah