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())
所有评论(0)