How to change the kernel of a jupyter notebook from the command line

Viewed 1234

I know that one can switch the kernel of a Jupyter notebook from within the notebook itself, for example, by going to the Kernel -> Change kernel menu.

I was just wondering if it's possible to do this programmatically with a shell script (or from command line).

I have many Jupyter notebooks that were in python kernel and need to be changed to the R kernel. Doing the conversion manually for all of them would be tedious. I searched around, but only found answers about how to change kernel via the Jupyter UI as linked above.

(This is with Ubuntu 20.04, and classic JupyterHub)

1 Answers

.ipynb files are, in fact, valid JSON. As kernel is saved in notebook metadata, you can edit it in text mode programmatically using Python itself, or with your favourite tool, for example jq.

Related