我可以在笔记本运行的 jupyterlab 内核中执行文件(或 python 的某些行)吗?

发布于 2025-01-10 02:41:07 字数 558 浏览 0 评论 0原文

我的笔记本有点笨重,我正在做一些重构,但这并不有趣。

我想知道是否可以从命令行执行此笔记本中的代码进行调试。

理想情况下,我会运行类似:

run-in-jupyter $notebook file.py

并查看命令行的输出。 jupyterlab中有一个解释器可以做到这一点,所以这让我认为这是可能的。

我进行了简短的搜索,但找不到太多

I've got a notebook that has got a bit unwieldy and I'm doing some refactoring which isn't fun.

I was wondering if it would be possible to execute code in this notebook from the command line for debugging.

Ideally, I would run something like:

run-in-jupyter $notebook file.py

and see the output from the command line. There is an interpreter in jupyterlab that can do this, so this make me think that it is possible.

I have a brief search but couldn't find much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笔芯 2025-01-17 02:41:07

jupyter console (pip install jupyter-console) 连接从内核到正在运行的 jupyter 内核。有关运行内核的详细信息可以在 jupyter 的运行时文件中找到,在我的盒子上,这些文件位于 ~/.local/share/jupyter/runtime 中。您可以使用 %config IPKernelApp.connection_file 找到与打开的工作簿对应的内核数据文件的路径,该路径类似于 ~/.local/share/jupyter/runtime/kernel-55da8a07 -b67d-4584-9ec6-f24e4a26cbbd.json

从命令行进行连接,

然后,您可以使用jupyter console --existing ~/.local/share/jupyter/runtime/kernel-55da8a07-b67d-4584-9ec6-f24e4a26cbbd.json

您可以将命令通过管道传输到如图所示

echo h=87 | jupyter console --existing 55da8a07-b67d-4584-9ec6-f24e4a26cbbd 'h=57' --simple-prompt -y

jupyter console (pip install jupyter-console) connects to a running jupyter kernel from the kernel. Details on running kernels can be found amongst jupyter's run time files, on my box these live in ~/.local/share/jupyter/runtime. You can find the path to the kernel data file corresponding to an open workbook with %config IPKernelApp.connection_file which will look something like ~/.local/share/jupyter/runtime/kernel-55da8a07-b67d-4584-9ec6-f24e4a26cbbd.json.

You can then connect from the command line with

jupyter console --existing ~/.local/share/jupyter/runtime/kernel-55da8a07-b67d-4584-9ec6-f24e4a26cbbd.json

You can pipe commands into it as shown

echo h=87 | jupyter console --existing 55da8a07-b67d-4584-9ec6-f24e4a26cbbd 'h=57' --simple-prompt -y
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文