LoginSignup
18
10

More than 3 years have passed since last update.

PyQt5をUbuntuで使うときにGUI周りでエラー (WSL2)

Last updated at Posted at 2020-10-05

PyQt5をwsl2で使おうとしたらトラブったので備忘録.
日本語の記事は1つだけapt installしたら解決すると言っているがしなかったので.

前提

トラブル

$ 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

いろいろな日本語ページに書いてあること

sudo apt install libxkbcommon-x11-0

これだけではだめだった.これも必要です!

解決手段

まず,libqeglfs.soのありかを見つける.

find / -name libqeglfs.so

など.だけどこれ多分実行時間がしんどいかもしれない.
例えば

export QT_DEBUG_PLUGINS=1

としてデバッグモードとし,目的のPythonファイルを実行すると

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)"

みたいなものが最後の方に出てきます(Pythonへのパスは path/to/pythonに書き換えています).

これが見つかったら,
https://forum.qt.io/topic/115732/could-not-load-the-qt-platform-plugin-xcb-in-even-though-it-was-found
などにあるように,

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

をしてやるとよいです.見にくかったら|grep "not found"を追加してやってもよいです.

これで足りないものがわかるので,例えば自分は


$ 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

だったので,

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

をしたら動くようになりました.めでたしめでたし.

18
10
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
10