Skip to content

Jupyter Notebook

Hints and tips for running Jupyter Notebook sessions

When running Jupyter Notebook sessions, Python can behave differently than when run from a script on in a terminal session.

Display issues

When trying to plot something I get the error:

    ImportError: Cannot load backend 'qtagg' which requires the 'qt' interactive framework, as 'headless' is currently running

This occurs because the Jupyter session has no access to a desktop environment with which to open a separate window. There are several solutions to this issue, depending on what your requirements are.

For displaying plots inline in the notebook, either install the Python module matplotlib-inline and then import matplotlib modules with import matplotlib-inline or put the following in a cell and execute it:

%matplotlib inline
or specify the backend in your code:
import matplotlibmatplotlib.use('module://matplotlib_inline.backend_inline')

For writing output to files without displaying use:

matplotlib.use('Agg')