8

I have an Jupyter notebook which generates the plots for some work. I would like to be able to run the notebook as part of a Makefile. So is there a way to instruct Jupyter to

1) Start a K=kernel

2) Open a specific notebook

3) Execute "Run All"

4) Shutdown the kernel

I imagine there will be issues with the security, but I can mark the notebook as trusted?

I have searched for help, but even getting the notebook to automatically Run All seems to be an issue.

For me, this is an important feature since once the exploratory part of work is over (for which the notebook is fantastic) it would be nice to quickly transition to the reproducible part!

Community
  • 1
  • 1
Greg
  • 11,654
  • 3
  • 44
  • 50

1 Answers1

12

I think you're looking for the jupyter nbconvert command.

Read an input notebook and produce a static HTML result:

jupyter nbconvert --to=html --ExecutePreprocessor.enabled=True notebook.ipynb

Read an input notebook and save the output back to the original:

jupyter nbconvert --to=notebook --inplace --ExecutePreprocessor.enabled=True notebook.ipynb

For more help, take a look at the help page:

jupyter nbconvert --help
shad
  • 1,770
  • 13
  • 12
  • Your second suggestion is the accepted answer, but replacing `--inplace` with`--output=/tmp/` so that the notebook is left untouched and no unwanted files are generated. Thanks – Greg Sep 10 '15 at 08:30
  • @Grey You may also use `--stdout` and redirect that to `/dev/null` to avoid creating any files. – Thijs van Dien Feb 10 '17 at 21:20