Fixing xcb Load Failures in PyQt5 on Windows Subsystem for Linux (WSL)

Giraldo PinoGiraldo Pino
1 min read

This morning I came across a complication I hadn't thought about before, how to use PyQt5 in Windows Subsystem for Linux (WSL). I'm familiar with PyQt5 in a Windows environment, due to my day job, but have only recently been transitioning to using WSL whenever possible outside of work.

I have a simple Python script to generate a QWidget with a couple buttons. However, I was promptly hit with the following error message:

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

Aborted

Thankfully, the fix turn out to be much easier than expected, thanks to ifyouaretea's response on askUbuntu.

# Ubuntu 22.04
export QT_QPA_PLATFORM="xcb"
sudo apt install libxcb-xinerama0 libqt5x11extras5

The installation takes a few minutes but once completed, PyQt5 was running smoothly and I could see the QWidget I had created!

0
Subscribe to my newsletter

Read articles from Giraldo Pino directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Giraldo Pino
Giraldo Pino