jupyter-notebook

How to clear Jupyter Notebook's output in all cells from the Linux terminal?


I have a problem when the output from a notebook is really long and it's saved into the notebook, any time I want to open this particular notebook again the browser crashes and can't display correctly.

To fix this I have to open it with a text editor and delete all output from that cell causing the problem.

I wonder if there is a way to clean all output from the notebook so one can open it again without problem. I want to delete all output since deleting a specific one seems more troublesome.


Solution

  • nbconvert 6.0 should fix --clear-output

    The option had been broken for a long time previously, bug report with merged patch: https://github.com/jupyter/nbconvert/issues/822

    Usage should be for in-place operation:

    jupyter nbconvert --clear-output --inplace my_notebook.ipynb
    

    Or to save to another file called my_notebook_no_out.ipynb:

    jupyter nbconvert --clear-output \
      --to notebook --output=my_notebook_no_out my_notebook.ipynb
    

    This was brought to my attention by Harold in the comments.

    Before nbconvert 6.0: --ClearOutputPreprocessor.enabled=True

    Same usage as --clear-output:

    jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace my_notebook.ipynb
    jupyter nbconvert --ClearOutputPreprocessor.enabled=True \
      --to notebook --output=my_notebook_no_out my_notebook.ipynb
    

    Tested in Jupyter 4.4.0, notebook==5.7.6.