28

I am trying to use Qt as matplotlib backend. i have checked it both on kaggle and google colab, but problem is same.

When i write

%matplotlib qt5

i got following error

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

When i print default backend, its already Qt5Agg

import matplotlib
print(matplotlib.get_backend())
Valeriy
  • 1,365
  • 3
  • 18
  • 45
Talha Anwar
  • 2,699
  • 4
  • 23
  • 62
  • 4
    I'm getting this in Jupyter Notebook launched from Windows Subsystem for Linux (WSL). On regular windows it works fine. – TomNorway Aug 05 '19 at 12:14

2 Answers2

10

This is happening because Google Colab and Jupyter run on virtual environments which do not support GUI outputs as you cannot open new windows through a browser.

Running it locally on a code editor(Spyder, or even IDLE) ensures that it can open a new window for the GUI to initialize.

For coding the GUI it is best to do it locally on a full-fledged code editor.

am-3
  • 142
  • 2
  • 7
0

There is a potential solution for this issue: Install and run a Xvfb instance in your server. Then check the environment variable $DISPLAY set properly. Try matplotlib use qt5 again.

Roaid
  • 316
  • 5
  • 17