[PYTHON] Error around GUI when using PyQt5 on Ubuntu (WSL2)

When I tried to use PyQt5 with wsl2, I had a trouble, so a memorandum. The Japanese article said that it would be solved if only one apt install was done, but I didn't.

Premise

--I want to use PyQt5 --The environment here is Ubuntu 18.04 on wsl2, but it should be common on Ubuntu. --It is assumed that the GUI environment of wsl (2) has already been built. Like putting in Xserver. --If you want to know here, please also see Installation of WSL2, construction of GUI environment and gnome-open of sshfs !!.

Trouble

$ main.py
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

What is written on various Japanese pages

sudo apt install libxkbcommon-x11-0

This was not enough. This is also necessary!

Solution

First, find out where libqeglfs.so is.

find / -name libqeglfs.so

Such. However, the execution time may be difficult. For example

export QT_DEBUG_PLUGINS=1

When you put it in debug mode and execute the target Python file

Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/path/to/python/bin/platforms" ...
Cannot load library /path/to/python/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/path/to/python/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so" : "Cannot load library /home/path/to/python/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: cannot open shared object file: No such file or directory)"

Something like this appears near the end (the path to Python has been rewritten as path / to / python).

If you find this https://forum.qt.io/topic/115732/could-not-load-the-qt-platform-plugin-xcb-in-even-though-it-was-found And so on

ldd /path/to/python/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so

You should do it. If it's hard to see, you can add | grep" not found ".

This will tell you what is missing, so for example,


$ ldd /path/to/python/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so | grep "not found"
        libxcb-icccm.so.4 => not found
        libxcb-image.so.0 => not found
        libxcb-keysyms.so.1 => not found
        libxcb-render-util.so.0 => not found
        libxcb-xinerama.so.0 => not found
        libxcb-icccm.so.4 => not found
        libxcb-image.so.0 => not found
        libxcb-keysyms.so.1 => not found
        libxcb-render-util.so.0 => not found
        libxcb-xinerama.so.0 => not found

Because it was

sudo apt install libxkbcommon-x11-0
sudo apt install libxcb-icccm4
sudo apt install libxcb-image0
sudo apt install libxcb-keysyms1
sudo apt install libxcb-render-util0
sudo apt install libxcb-xinerama0

Then it started to work. Congratulations.

Recommended Posts

Error around GUI when using PyQt5 on Ubuntu (WSL2)
Error, warning when using TensorFlow on Mac
CPU usage is 100% when using pygame on Ubuntu 16.04
Troublesome story when using Python3 with VScode on ubuntu
Display GUI messages on Ubuntu
wsl Install PostgreSQL on Ubuntu 18.04
Install Docker on WSL Ubuntu 18.04
Run MuJoCo on WSL (2) (also GUI)
Introducing Python using pyenv on Ubuntu 20.04
# Solution when pip install gives an error when using Anaconda on Windows 10
[Super basic] Docker command procedure manual when using Ubuntu on Mac
Using a serial console on Ubuntu 20.04
Error log output method when using Bottle framework on GAE / Python
Run Yocto on Ubuntu using QEMU.
Using Kali Linux Gui with WSL2
Error resolution when installing numba on macOS
RTKLIB 2.4.3 CLI version GUI version installed on Ubuntu 18.04
Error that occurred in OpenCV3 and its solution Precautions when using OpenCV3 on Mac
Linux Ubuntu16.04 I got a little scary error when I ran a command using sudo
A addictive story when using tensorflow on Android
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Python development on Ubuntu on AWS EC2 (using JupyterLab)
Notes for using TensorFlow on Bash on Ubuntu on Windows
Eliminates SSL error when PIP Install on Windows.
Create a GUI on the terminal using curses
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
I get an error when I try to raise Python to 3 series using pyenv on Catalina