Cookies on this website

We use cookies to ensure that we give you the best experience on our website. If you click 'Accept all cookies' we'll assume that you are happy to receive all cookies and you won't see this message again. If you click 'Reject all non-essential cookies' only necessary cookies providing core functionality such as security, network management, and accessibility will be enabled. Click 'Find out more' for information on how to change your cookie settings.

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')