What is the best method to load a Jupyter notebook session into Spyder?

DougR picture DougR · Jun 16, 2017 · Viewed 32.3k times · Source

Edit: See Spyder Notebook Plugin... https://github.com/spyder-ide/spyder-notebook


I would like to load a Jupyter notebook into Spyder and activate the current Jupyter Python kernel in an Spyder Ipython console. I was hoping this would allow me to use the Spyder editor, console and variable explorer whilst developing in Jupyter. Using the code below in Jupyter, I have been able to load up a converted notebook. In addition, I can open the current kernel in a new console manually. However, the variable explorer doesn't display variables from the connected console.

I would like to:

1) From Jupyter, automatically open the current Jupyter kernel in the Spyder IPython Console
2) Get the Spyder variable explorer to work with a connected kernel

Any ideas? Does anyone have a better method than that listed below?


Open Jupyter notebook and kernel in Spyder:

Get current notebook name

%%javascript
var nb = IPython.notebook;
var kernel = IPython.notebook.kernel;
var commandFileName = "theNotebook = " + "'"+ nb.notebook_path +"'";
kernel.execute(commandFileName);

Convert notebook to plain python script

get_ipython().system('jupyter nbconvert --to script "' + theNotebook + '"')

Open python script in Spyder

get_ipython().system('spyder "' + theNotebook.replace('.ipynb', '.py') + '"')

Get kernel json connection file

import ipykernel
print("Copy and paste this into Spyder diaolgue box:\nConsoles~'Connect to an existing kernel':\n")
print(ipykernel.connect.get_connection_file())

Answer

Carlos Cordoba picture Carlos Cordoba · Jun 16, 2017

(Spyder developer here) This will be solved once we make our own Notebook plugin to start Spyder kernels.

We're working right now to release a first version of that plugin with good desktop integration. Then we'll proceed to integrate it with the other Spyder plugins (such as the Variable Explorer) and for that we need to make the notebook to start Spyder kernels.