0

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

Att Righ
  • 1,439
  • 1
  • 16
  • 29

1 Answers1

1

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
Att Righ
  • 1,439
  • 1
  • 16
  • 29