Explore using the interactive window as a console for notebook kernels
See original GitHub issueFrom discussion with @greazer @rchiodo @claudiaregio @rebornix
Existing feature requests:
- https://github.com/microsoft/vscode-jupyter/issues/4573
- “I add some cells to try something out and I don’t want to lose them, but I don’t want them in my ‘main’ notebook.”
- https://github.com/microsoft/vscode-jupyter/issues/6484
- “…interactive command line that is connected to a jupyter notebook…”
- https://github.com/microsoft/vscode-jupyter/issues/6033
- “…create interactive Python consoles connected to specific notebook kernels. The main usecase is to be able to work interactively based on the state of a notebook without having to tinker with the notebook itself.”
- “…have an ability to launch an IPython shell (within VS Code) which is binded to the kernel of a specific notebook (so all objects defined in the notebook are accessible there etc.)…”
Proposed experience:
- Command contributed to
notebook/cell/title
to open interactive window connected to same kernel - Command contributed to
interactive/cell/title
to paste code back into notebook - Kernel picker to be hidden
- Sys info cell to indicate the notebook association
- Context keys to hide interactive window specific functionality
- Title should say ‘Scratchpad’
- Should the interactive window immediately receive focus when created?
Bare-bones prototype:
Open questions
- Should users be able to start multiple interactive consoles? Original prototype has scratchpad singleton
- Should the scratchpad contain just the one cell (fully matching https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/scratchpad/README.html behavior) or be a full interactive window?
- Introduce keybinding or similar to copy code (otherwise user has to move mouse literally the entire span of the screen)
Engineering notes:
- Summary: Jupyter extension needs to refactor our
VSCodeNotebookController
wrapper,IKernel
, and the cell execution codepath to allow- an
IKernel
that is currently mapped to ajupyter-notebook
controller which has been selected for a givenjupyter-notebook
NotebookDocument - to be reused for an
interactive
controller that is selected for a giveninteractive
NotebookDocument
- an
- Current state/background
- Currently vscode.NotebookControllers are per-notebookType, so to get our kernels to show up for interactive windows, each of our kernels is registered twice with VS Code–once for the
jupyter-notebook
notebookType and once for theinteractive
notebookType - Our code currently assumes a 1-1 relationship between a VS Code NotebookController and our internal IKernel objects, i.e. controller is passed into IKernel constructor and then passed all the way down through the constructors of KernelExecution, CellExecutionQueue, CellExecution etc. in order to create the notebook cell execution task
- Controllers can only create execution tasks for the NotebookDocument that they are currently associated with in VS Code
- Our code currently also starts a new kernel for each new NotebookDocument in
kernelProvider.getOrCreate
- Interactive window needs to be passed a controller ID at creation to pick up the right controller (alternative is
notebook.selectKernel
or similar after the window is created, but we’ve discussed this and decided not to do it). NotebookDocument is returned frominteractive.open
, so given thejupyter-notebook
controller currently selected for a Jupyter notebook, we need to find the matchinginteractive
controller that we told VS Code about, and make sure that the underlying kernel is reused - Note, this also means that if we want arbitrary notebooks to be able to start an interactive session, then all those extensions must ensure that they return the same instance for
jupyter-notebook
andinteractive
notebookTypes (not guaranteed to work OOB)
- Currently vscode.NotebookControllers are per-notebookType, so to get our kernels to show up for interactive windows, each of our kernels is registered twice with VS Code–once for the
Issue Analytics
- State:
- Created 2 years ago
- Reactions:39
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Working with Jupyter code cells in the Python Interactive window
To use the window as a console, open it with the Jupyter: Create Interactive Window command from the Command Palette. You can then...
Read more >Linking VS Code interactive window to running Jupyter ...
Linking VS Code interactive window to running Jupyter notebook ... JupyterLab the is accomplished with the New Console for Notebook command.
Read more >Connecting to your notebook kernel using Jupyter console
Jupyter notebooks are a great way to explore data using Python (and other languages as well). Having a visual representation of your code...
Read more >IPython Console — Spyder 5 documentation
To connect to a local kernel that is already running (e.g. one started by Jupyter notebook),. Run %connect_info in the notebook or console...
Read more >Code Consoles — JupyterLab 3.6.0b0 documentation
Code consoles also display rich output, just like notebook cells. ... Use the up and down arrows to browse the history of previously-run...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also join the petition. I recently switched from JupyterLab to VSCode, and this is an especially useful feature that makes it easier the daily work. It is quite common that at a certain moment we want to do some test with the variables, etc. in the notebook, and it is a bit clumsy to have to create new cells and then delete them again, especially when it is something that can be done in seconds from the interactive shell.
I think that all of us who work often with Jupyter Notebooks, would be very grateful if you could add this function.
I would be glad to see this implemented. My workflow around this feature would be like this:
Right now I can do it only in Interactive mode (with blocks starting with # %%), but this approach lacks of visual outputs I can have in notebooks.