17

I want to use the interactive plots in jupyter, but when switching the backend to notebook, I get the warning: Warning: Cannot change to a different GUI toolkit: notebook. Using qt5 instead.

This happens on Windows 10, Anaconda 1.8.7, jupyter 5.5.0, python 3.6.5 and matplotlib 2.2.2.

Minimal working example:

import matplotlib.pyplot as plt
%matplotlib notebook

Output:

Warning: Cannot change to a different GUI toolkit: notebook. Using qt5 instead.

I found some question here where the problem is the other way around, but could not find anyone having this problem yet. In some cases, importing ipympl is mentioned as a solution, but this does not change anything in my case.

Any hints?

Christian Weber
  • 261
  • 1
  • 2
  • 8
  • 1
    Does the same happen when inverting the order of the commands? First, `%matplotlib ...` then `import ...`? – ImportanceOfBeingErnest Oct 08 '18 at 14:28
  • Yes, it does. But I just found out that the notebook backend is not registered in matplotlib.rcsetup.all_backends: `matplotlib.rcsetup.all_backends: ['GTK', 'GTKAgg', 'GTKCairo', 'GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'gdk', 'pdf', 'pgf', 'ps', 'svg', 'template']` – Christian Weber Oct 08 '18 at 19:17
  • Well, it's called `'nbAgg'` here. But I think this list would even list backends, if they were not available at all. – ImportanceOfBeingErnest Oct 08 '18 at 19:26
  • I don't have your exact versions (also jupyter consists of several parts, not sure what (5.5.0) refers to) but at least in my setup I cannot reproduce this problem. – ImportanceOfBeingErnest Oct 08 '18 at 19:27
  • And you also have Win10 and Anaconda? I never had the problem in Ubuntu, but it seems like this only occurs in Win10. – Christian Weber Oct 08 '18 at 20:40
  • I have windows 8.1 and miniconda, but I don't think its system dependent at all. It's rather some issue with the exact versions in use, I suppose. – ImportanceOfBeingErnest Oct 08 '18 at 20:47
  • Hmm... Now I created an environment with Python 3.7.0, Jupyter notebook server 5.7.0, ipython 6.5.0 and matplotlib 3.0.0 - and the problem still persists. – Christian Weber Oct 09 '18 at 09:50
  • 2
    So there is [no problem](https://i.stack.imgur.com/FttYw.png) when not setting any backend beforehands for me. Your problem can be reproduced when [explicitely setting a backend](https://i.stack.imgur.com/rnBPV.png). This means somewhere in your configuration the backend is already set to qt. – ImportanceOfBeingErnest Oct 09 '18 at 10:19
  • Thanks for the hint, this pointed me in the right direction to fix the problem! I will give it a try and write the answer myself now. – Christian Weber Oct 11 '18 at 08:59

2 Answers2

9

As ImportanceOfBeingErnest pointed out in the comments, my problem was related to the backend already being set when jupyter starts. However, as mentioned in this post, the backend needs to be set in the ipython_config.py, not the jupyter_notebook_config.py.

After restarting the notebook server, I can switch between backends as described here.

Christian Weber
  • 261
  • 1
  • 2
  • 8
5

You must put %matplotlib widget in the very beginning of the Jupyterlab

Ulysses
  • 141
  • 2
  • 2