Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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()) 
like image 808
DougR Avatar asked Jun 16 '17 11:06

DougR


People also ask

How do you import Jupyter notebooks in Spyder?

You can also open any Jupyter Notebook inside Spyder. For this go to the options menu at the top right of the pane and click Open, which will allow you to look for ipynb files in your computer. Click any notebook that you want to open inside Spyder and you will be able to see it as a new tab in the Notebook pane.

Can Spyder run Jupyter Notebook?

Project description This package allows the Jupyter notebook to run inside Spyder as a plugin.

How do you load Jupyter notebooks?

Double-click on the Jupyter Notebook desktop launcher (icon shows [IPy]) to start the Jupyter Notebook App. The notebook interface will appear in a new browser window or tab. A secondary terminal window (used only for error logging and for shut down) will be also opened.

Which is faster Jupyter Notebook or Spyder?

A code ran in jupyter is ran through the python interpreter, the same interpreter that pycharm or spyder would use and hence there is no reason why jupyter would run faster.


1 Answers

(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.

like image 52
Carlos Cordoba Avatar answered Nov 01 '22 13:11

Carlos Cordoba