How to run all cells at once programmatically?

I want to run all the cells in a jupyter notebook .ipynb file all at once. I have tried nb-convert but it is creating a new output file to this action. I don’t want to create a new output file rather than that I want to see the output for running all cells in the main .ipynb file without creating new output.ipynb file.

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.)

1 Like