简体   繁体   中英

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.

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.

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

This works for me (Windows 10):

  1. conda install qtconsole
  2. pip install PyQt6
  3. DOSbox run ipython qtconsole . . .
    控制台
  4. File > New Tab with Existing kernel, as shown above picture.
  5. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM