Ctrl K

Jupyter Notebook to HTML

Convert a Jupyter notebook to a clean HTML file with output only.

Export a notebook as HTML without showing the source code so you can share results as a standalone page.

Quick reference

jupyter nbconvert --to html --no-input your_notebook.ipynb

# Safer when working inside a venv
python -m jupyter nbconvert --to html --no-input your_notebook.ipynb

Create a venv and install nbconvert

For a new virtual environment, install nbconvert first. This is enough when the notebook already has saved outputs and you only need to export them to HTML.

python -m venv .venv
source .venv/bin/activate

python -m pip install --upgrade pip
python -m pip install nbconvert

Run the conversion through Python when you want to make sure the active venv is used.

python -m jupyter nbconvert --to html --no-input your_notebook.ipynb

Install for site workflow

For a site workflow that exports notebooks repeatedly, install nbconvert, jupyter, and ipykernel in the same venv.

python -m pip install nbconvert jupyter ipykernel

Execute during conversion

If the notebook does not already have saved outputs, execute it during conversion. The venv must also contain the notebook dependencies needed by the notebook itself.

python -m pip install nbconvert ipykernel

python -m jupyter nbconvert --to html --no-input --execute your_notebook.ipynb

Verify the venv tools

Check that Python, pip, and jupyter all come from the active virtual environment.

which python
which pip
which jupyter

python -m jupyter nbconvert --version

# Expected paths should point into .venv:
# /home/example-user/projects/tools/nbconvert/.venv/bin/python
# /home/example-user/projects/tools/nbconvert/.venv/bin/pip
# /home/example-user/projects/tools/nbconvert/.venv/bin/jupyter

Flags

  • --to html - output format
  • --no-input - strips all code cells from the output, leaving only results and markdown
  • --execute - runs the notebook before writing the HTML output

The output file is placed in the same directory as the notebook with a .html extension. To write to a different location:

python -m jupyter nbconvert --to html --no-input your_notebook.ipynb --output-dir ./exports