GeezerVison is showing github.com — [ENH]: WSL support · Issue #32381 · matplotlib/matplotlib
[ENH]: WSL support #32381DescriptionProblem
Actually it is not user-friendly to run Matplotlib on WSL.
Moreover, this answer python - Show matplotlib plots (and other GUI) in Ubuntu (WSL1 & WSL2) - Stack Overflow is outdated.
Since WSL2 implements the Wayland protocol and the OpenGL API, Matplolib should detect it is running on WSL and select automatically the right backend or raises an informative error message.
To detect WSL, we can rely on:
uname kernel
- or the presence of
/etc/wsl-distribution.conf
For the backend, we can use:
- Qt Agg with PyQt5 and set the env
QT_QPA_PLATFORM=wayland (PySide2 seems to crash)
- to be completed Qt6 GTK Vulkan...
QT_QPA_PLATFORM is mandatory since Qt is probably not able to detect WSL and select the right backend.
RESUME for USERS: YOU DON'T NEED X11 ! It should work out of the box !
Proposed solution
No response Activitytacaswell commented on Sep 23, 2026 scottshambaugh commented on Sep 23, 2026 I'm happy to trial run the setup instructions on this. I will note that the VcXsrv setup in that stack overflow is not outdated, and still works - I set it up on a fresh WSL2 machine a few weeks ago. But an out-of-the box solution would be better, and we should document the setup here regardless. FabriceSalvaire commented on Sep 24, 2026 I did further test on WSL Ubuntu
- Matplolib Qt backend works with Qt6 (I missed this point for my first post...)
matplotlib.use('QtAgg') requires pyside6 and doesn't need the QT_QPA_PLATFORM env to be set. I guess Qt6 Platform Abstraction was improved...
- Qt5 must be deprecated (it is no longer supported by Qt and we have Qt6)
- pyside2 is not as good as PyQt5, but now pyside6 is fine and supported by Qt
Matplotlib.use('QtCairo') also works but requires cairocffi
- the GTK backend is not a first choice alternative since it depends on pygobject that need to be compiled...
- Notice that Tk and X11 are outdated solutions !!!
My Qt6 test was reproducible in a PowerShell terminal, thus the installation procedure is quite similar for Windows and WSL:
- install Python using winget
- install Astral uv using the user manual procedure
- start a fresh project
- uv install matplolib and pyside6
versus
- install a WSL distribution (Python is already there)
- install Astral uv using the user manual procedure
- start a fresh project
- uv install matplolib and pyside6
Please note, that lambda users will read the quick start guide and not the Backend page which is full of (outdated) details...
Indeed, according to the Installation page, uv add matplotlib pyside6 is the way to go for 99.99% of your users on any platform ! rcomer commented on Sep 26, 2026 Note that the conda-forge recipe includes pyside6, so anyone following the conda instructions will automatically get that. Does pixi also pull from conda-forge? rcomer commented on Sep 26, 2026 rcomer commented on Sep 26, 2026
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|