LoginSignup
7
12

More than 3 years have passed since last update.

WSLのpython環境でGUI周りではまったこと

Last updated at Posted at 2019-11-27

はじめに

先日wslにpython環境を構築したばかりで,GUIを含んだプログラムを実行していなかったので試しに実行してみたところ,エラーで詰まったのでその対処を備忘録として残します.

追記(2020/11)

下記のstackoverflowのページでWSL2も含めた一連の解決策が乗っているのでこちらも参照してください.

python - Show matplotlib plots (and other GUI) in Ubuntu (WSL1 & WSL2) - Stack Overflow

実行したプログラムの概要

実行しようとしてはまったのはPyQt5を使用したGUIプログラムです.matplotlibによる描画も含んでいます.
Anaconda環境では何の追加設定もなしに実行可能なプログラムになっています.

エラーの内容

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
プログラムを実行したところ上記のエラーが出ました.

調べると同じような状況に遭遇した方がいました.
`qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.` というエラーが起きたときの対処 - Qiita

やったこと

下記を実行しました.

sudo apt install libxkbcommon-x11-0

※ 上記記事には~/.bashrcにexport QT_DEBUG_PLUGINS=1を記載するよう書いていますが,これはデバッグ用のものなので不要です.

ただこれの実行前に,以下を実施しています.

  • Qt, PyQt5, SIPをインストールした.(プログラムがPyQt5を使用しているようだったため,これらをインストールした.)
  • tkinterとXserverをインストールし,表示先ディスプレイの設定をした.(wslのUbuntuにはGUI機能がないため,matplotlibの描画やQtのGUI画面の表示に必要)1

matplotlibなどのGUIを含むプログラム実行時には,Xserverを起動している必要があります.起動せずに実行すると,以下のエラーが出ます.

qt.qpa.xcb: could not connect to display :0.0 
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 (core dumped) 

もしかしたら不要な部分があるかもしれませんが,僕の場合はこれで解決できました.ご参考まで.

7
12
0

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
7
12