PyQT/Matplotlib in Windows Subsystem for Linux

  1. install Xming X11 server for WSL
  2. install QT

     apt install libqtgui4
    
  3. setup Anaconda Python on WSL
  4. install Matplotlib

     conda install matplotlib
    

Matplotlib in WSL notes

Install Matplotlib for WSL using system Python

If you don’t want to use Anaconda Python for WSL, you can use Matplotlib in system Python by:

apt install python-matplotlib

Non-X11 Matplotlib use

You can make plots using .savefig() without X11 installed in WSL.

Start your Python code with:

import matplotlib
matplotlib.use('agg')
print(matplotlib.get_backend())

you should see agg printed. This will allow writing figures to disk, but will disallow displaying them on screen.

Matplotlib errors on WSL

if

import matplotlib

gives error

ImportError: libSM.so.6: cannot open shared object file: No such file or directory

then consider installing X11 in Windows Subsystem for Linux.

Leave a Comment