microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.27k stars 284 forks source link

Connect to existing Local Kernel #9517

Open DonJayamanne opened 2 years ago

DonJayamanne commented 2 years ago

FYI - This feature is for the scratch path.

Connecting to exiting live remote kernels is simple:

For local kernels, we have no such concept - we must create a controller that points to the live local kernel. Suggestions

Notes:

Thoughts:

DonJayamanne commented 2 years ago

Outcome:

For now, enable this feature only in the pre-release (insider version).

Trezorro commented 1 year ago

Hi @DonJayamanne what is the status on integrating this into the stable vscode version? This is a must have!

DonJayamanne commented 1 year ago

@Trezorro please could you provide an example of your use case, thanks

kylebarron commented 1 year ago

I use this all the time in Atom's Hydrogen, and now that Atom is breaking in more places it would be nice to have this support in vscode.

My use case is mostly in having an interactive and persistent Jupyter session while developing data-intensive libraries. Say I have a package split into multiple files:

# a.py
import pandas as pd

def create_dataframe():
    return pd.DataFrame({'a': [1, 2, 3]})
# b.py
from a import create_dataframe

def use_dataframe()
    df = create_dataframe()
    # use df

Say that I'm editing b.py but realize that I need to modify the behavior of create_dataframe in a.py. Without being able to share one Jupyter kernel across both files, I need to restart the kernel that b.py is using so that I can get the updated create_dataframe definition. But when both files are able to share the same Jupyter kernel, I can re-evaluate create_dataframe and use that function without needing to restart the kernel that b.py is using. Avoiding a restart of the kernel is very useful when the steps to re-create the data in memory take a long time.

Here's a recorded example of how my desired behavior works in Hydrogen

https://user-images.githubusercontent.com/15164633/204104970-2c27a3f6-0187-4b44-9cc5-3319056e8f0b.mov

  1. First I create a new Jupyter kernel in a.py and execute its code
  2. Then I attach to the same kernel in b.py, run create_dataframe and check that its output is expected
  3. Then I realize I need to change create_dataframe in a.py. I can make a change to create_dataframe, re-execute that function definition, and then call it in b.py without restarting the kernel.

This works because create_dataframe is defined in the running kernel as <function __main__.create_dataframe()>. But if this code is loaded as a library, it will still work because of from a import create_dataframe.

vttrifonov commented 1 year ago

I use the ipynb for presentation (cells with few lines of code and explanation around them) and py code with all complexities (making widgets, generating data, plots, etc) is separate. I work mostly within VSCode and use Jupyter rarely... I usually work on code and presentation/notebook in parallel going back and forth. I will nibble at the code and add a cell that captures the gist. Vice versa, I can prototype within the notebook and then move it to the code. Either way having a connection between IW and the notebook is a boon. In my current workflow, I run a remote (mostly localhost) Jupyter outside of VSCode and then connect the notebook and the IW to this remote. It works fine but needless to say having to run Jupyter outside, get the URL, paste in VSCode, etc is a nuisance... Sometimes I start with the IW and then connect the notebook to it (IW shows as default.ipynb notebook). Sometimes the other way around.

It seems natural to provide the same functionality within VSCode (perhaps as a new type of remote: a local virtual kernel)

Shayan-B commented 1 year ago

It would be great if we could have this feature in vs code, for DS this is a must have feature.

DonJayamanne commented 1 year ago

@Shayan-B Please do upvote this issue, thats how we prioritize issues.

wetlandscapes commented 1 year ago

This is a critical feature for using notebooks. I basically can't use VS Code notebooks without having a connected terminal to prototype code. Having the interactive terminal connected to a .py file is nice, but most of my work is in notebooks, and having to constantly export from .ipynb to .py (and the reverse) is just too much friction, so I just end up launching Jupyter Lab and skipping VS Code.

DonJayamanne commented 1 year ago

so I just end up launching Jupyter Lab and skipping VS Code.

Thanks but how do you achieve this feature request today in Jupyter lab?

but most of my work is in notebooks, and having to constantly export from .ipynb to .py (and the reverse) is just too much friction

looks like you need a separate feature This issues don’t seem to fulfill your requirements above You seem to want to just switch between ipynb and py files , but there’s no mention of sharing the same kernel session Also I am not sure how you can achieve that in Jupyter lab (you’ve indicated that you can do that)

wetlandscapes commented 1 year ago

Thanks for the quick response and the clarifying questions. In Jupyter Lab you right-click the active notebook of interest and select "New Console for Notebook". And that's it. The attached gif gets at the functionality.

jupyer-lab_interactive_notebook_terminal

mocquin commented 1 year ago

@wetlandscapes this is the main feature I am missing since I switched from jupyterlab to vscode

abhirajD commented 1 year ago

Thanks for the quick response and the clarifying questions. In Jupyter Lab you right-click the active notebook of interest and select "New Console for Notebook". And that's it. The attached gif gets at the functionality.

jupyer-lab_interactive_notebook_terminal

Similarly, in jupyter-notebook, you can use THIS extension. Here you just use ctrl-b to open an interactive scratchpad.

Major missing this feature.

scratchpad-demo

AaronCreighton commented 10 months ago

Here is a version of this one I like Explore using the interactive window as a console for notebook kernels

thehappycheese commented 10 months ago

<3 I know many users at my work who refuse to switch from Spyder because this feature is missing.

Yefee commented 7 months ago

Please make it happen. This is a must-have feature in DS. ;-)