我可以在笔记本运行的 jupyterlab 内核中执行文件(或 python 的某些行)吗?
我的笔记本有点笨重,我正在做一些重构,但这并不有趣。
我想知道是否可以从命令行执行此笔记本中的代码进行调试。
理想情况下,我会运行类似:
run-in-jupyter $notebook file.py
并查看命令行的输出。 jupyterlab中有一个解释器可以做到这一点,所以这让我认为这是可能的。
我进行了简短的搜索,但找不到太多
- 如何运行来自终端的 .ipynb Jupyter Notebook? 我明确不想这样做(我想在现有实例中运行命令)
- 有 这个库 但这似乎很复杂,我在人们无法使用互联网的图书馆
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
- How to run an .ipynb Jupyter Notebook from terminal? I explicitly don't want to do this (I want to run commands in an existing instace)
- There is this library but this seems quite involved and some of the results I found on the internet where people not being able to use the library
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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
您可以将命令通过管道传输到如图所示
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