Executing pages of your book

    Sometimes you'd like to execute each page's content before building its HTML - thisensures that the outputs are up-to-date and that they still run. Jupyter Bookhas the ability to execute any code in your content when you build each page's HTML although by default this is disabled for notebook and simple markdown documents.

    Jupyter Book will decide whether to execute your book's content based on the types of files used to store your content. By default, Jupyter Book assumes that :

    • simple raw markdown files (.md, no Jupytext header) will also not be executed: Jupyter Book assumes that any code blocks were meant for viewing only, not running;

    Jupyter Book provides a convenience command-line function that executesone or more Jupyter Notebooks and stores the outputs inline within the same ipynb file. This provides a straightforward way of ensuring that source notebook files contain freshly computed cell outputs when you create your Jupyter Book.

    It will simply execute the notebook and insert the code cell outputs in-place.

    You can also specify a folder with a collection of pages as the first argument:

    1. jupyter-book run path/to/notebook_folder

    In this case, all notebooks in this folder and sub-folders will be run in-place.

    jupyter-book build —execute

    This will cause each .ipynb and jupytext-formatted page to be executed when it is built.In this case, the source content files will not be modified, but the code execution outputs will be placed in each page's HTML.

    Remember that the HTML for each page is cached until you update your content. Thefirst time you run jupyter-book build —execute, each page of your book will be runand converted to HTML which may take some time. However, after the first run, only the pages that have been updated will be executed and converted to HTML, which should lead to subsequently faster build times as you update your content.

    This page was created by The Jupyter Book Community