'Can VSCode interact with the kernel of current Jupyter notebook?
In VSCode, a script with:
#%%
a = 3
creates a Jupyter cell. Running the cell starts Jupyter server and evaluates the code in Python Interactive window.
I would like to interact with this session and pass print(a)
to it from a console, without modifying the Jupyter notebook. Is that possible? I cannot find a way to open a Python session in which a
would be defined.
Solution 1:[1]
I'd suggest logging a suggestion from our GitHub: https://github.com/Microsoft/vscode-python/issues
This might be similar to what you're asking for. https://github.com/Microsoft/vscode-python/issues/3101
This would allow you to type temporary code into the interactive window. If you didn't like it, you could delete it.
Solution 2:[2]
You could call ipython's %qtconsole
magic command
#%%
%qtconsole
This opens up a separate jupyter qt-console window which points at the same kernel as the vbcode 'notebook'.
Solution 3:[3]
This works for me (Windows 10):
conda install qtconsole
pip install PyQt6
- DOSbox run
ipython qtconsole
. . . - File > New Tab with Existing kernel , as shown above picture.
- Select an existing kernel (.json file). I check variable value to know which one is the correct target or by the date-time of the .json files.
6. then you can do your experiments onto the existing .ipynb notebook.
Jupyter Lab is much much better. You can open any .py and select an existing .ipynb as its kernel. Then highlight anything on the .py and press Shift-Enter to execute the highlight. I have a .py that collects most useful code snippets and it keeps everything I tried. Why VS code can't do this? Or it can actually already?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | rich - MSFT |
Solution 2 | asrbrr |
Solution 3 | H.C.Chen |