[英]Can VSCode interact with the kernel of current Jupyter notebook?
In VSCode, a script with:在 VSCode 中,脚本包含:
#%%
a = 3
creates a Jupyter cell.创建一个 Jupyter 单元格。 Running the cell starts Jupyter server and evaluates the code in Python Interactive window.
运行单元会启动 Jupyter 服务器并评估 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.我想与这个 session 交互并从控制台将
print(a)
传递给它,而不修改 Jupyter 笔记本。 Is that possible?那可能吗? I cannot find a way to open a Python session in which
a
would be defined.我找不到打开 Python session 的方法,其中将定义
a
。
I'd suggest logging a suggestion from our GitHub: https://github.com/Microsoft/vscode-python/issues 我建议从我们的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
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 您可以调用ipython的
%qtconsole
魔术命令
#%%
%qtconsole
This opens up a separate jupyter qt-console window which points at the same kernel as the vbcode 'notebook'. 这将打开一个单独的 jupyter qt-console窗口,该窗口指向与vbcode'notebook'相同的内核。
This works for me (Windows 10):这对我有用(Windows 10):
conda install qtconsole
pip install PyQt6
ipython qtconsole
. ipython qtconsole
。 . 6. then you can do your experiments onto the existing.ipynb notebook. 6. 然后你可以在 existing.ipynb notebook 上做你的实验。
Jupyter Lab is much much better. Jupyter Lab 要好得多。 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.
您可以打开 any.py 和 select 和 existing.ipynb 作为其 kernel。然后突出显示 .py 上的任何内容并按 Shift-Enter 执行突出显示。 I have a.py that collects most useful code snippets and it keeps everything I tried.
我有一个收集最有用的代码片段的.py,它保留了我尝试过的所有内容。 Why VS code can't do this? Or it can actually already?
为什么 VS code 不能这样做?或者它实际上已经可以了?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.