How to run all cells at once programmatically?

There’s a flag, --inplace, you can use to run the notebook ‘in place’ with jupyter nbconvert. Go here in the documentation and scan down a little ways until you see --inplace. That option will also come up as one of the options listed if you run jupyter nbconvert --help. It is the eighth one listed under ‘Options’.

You can also use jupytext, probably better known as a tool for conversion of notebooks to text forms and back again, to execute the notebook without any conversion. By default it overwrites the notebook without need any extra flag. Example command:

jupytext --execute my_notebook.ipynb 

Jupytext is super handy when dealing with Jupyter notebook.

jupyter nbconvert doesn’t save on a per cell basis. So if you want to monitor the progress externally cell-by-cell as another task executes the notebook, you can execute the notebook with papermill. (I keep meaning to check if jupytext waits until the execution is complete before updating the output or not.)

2 Likes