Can I run Jupyter notebook cells in commandline?

nbconvert (a jupyter tool for notebook conversion) allows you to do this without any extra packages:

Just go to your terminal and type

$ jupyter nbconvert --to notebook --inplace --execute mynotebook.ipynb

Source

(Thanks Stephan for suggesting the --inplace flag)

NOTE: This said, I'd try to convert everything you need to a proper script. Jupyter notebooks are thought to use for exploring and sharing results, and not as a replacement of traditional programs.


You can use runipy to do this.

runipy will run all cells in a notebook. If an error occurs, the process will stop.

$ pip install runipy

$ runipy MyNotebook.ipynb

There are also commands for saving the output file as a notebook or an html report:

$ runipy MyNotebook.ipynb OutputNotebook.ipynb

$ runipy MyNotebook.ipynb --html report.html


You can also try papermill which allows you to execute notebooks from command line, and also pass parameters:

For example:

$ papermill mynotebook.ipynb mynotebook_output.ipynb -p start "2017-11-01" -p end "2017-11-30"

You can also run it without passing any parameter.