2017/04/25

Ubuntu 16.04 に wxPython (Python3用) をインストール

2018/3/8 追記
wxPython 4.0.1 では微妙に依存関係が変わったようなので書き直しました。 公式に Wheel が用意されたので、簡単にインストール出来ます。

Linux に wxPython をインストールする方法 | 穀風

pip で依存関係の多いライブラリをインストールするのは結構面倒くさいです。 今回、 Python3 用の wxPython をインストールしようと思ったら結構はまったので自分用メモ。

今回は様々な依存関係を断つために、Docker 上にインストールしてみました1。 Docker 便利だなー。

出来上がった Dockerfile は以下。 重要なのは 4行目の依存パッケージになります。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FROM ubuntu:16.04
 
RUN apt update && apt -y install python3 python3-pip \
  libgtk2.0-dev mesa-common-dev libglu1-mesa-dev python-gst0.10-dev libwebkit-dev
 
RUN pip3 install wxPython
 
# Replace 1000 with your user / group id
ARG uid=1000
ARG gid=1000
RUN groupadd -g ${uid} tester && \
    useradd -u ${gid} -g tester -r tester && \
    mkdir /home/tester && \
    chown ${uid}:${gid} -R /home/tester
 
USER tester
WORKDIR /home/tester

ビルド & 実行方法は以下を参照してください。

以下のスクリプトを実行すると

1
2
3
4
5
6
7
8
9
10
import wx
 
def main():
    app = wx.App()
    frame = wx.Frame(None, -1, 'main')
    frame.Show(True)
    app.MainLoop()
 
if __name__ == '__main__':
    main()

空の Frame が表示されました。

以下、各依存関係のエラーメッセージと対策を備忘録的に。

GTK+

エラーメッセージは以下。

    checking for GTK+ - version >= 2.6.0... Package gtk+-2.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gtk+-2.0.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gtk+-2.0' found
    Package gthread-2.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gthread-2.0.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gthread-2.0' found
    no
    *** Could not run GTK+ test program, checking why...
    *** The test program failed to compile or link. See the file config.log for the
    *** exact error that occurred. This usually means GTK+ is incorrectly installed.
    checking for pkg-config... (cached) /usr/bin/pkg-config
    checking for GTK+ - version >= 3.0.0... Package gtk+-3.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gtk+-3.0.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gtk+-3.0' found
    Package gthread-2.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gthread-2.0.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gthread-2.0' found
    no
    *** Could not run GTK+ test program, checking why...
    *** The test program failed to compile or link. See the file config.log for the
    *** exact error that occured. This usually means GTK+ is incorrectly installed.
    checking for gtk-config... no
    checking for GTK - version >= 1.2.7... no
    *** The gtk-config script installed by GTK could not be found
    *** If GTK was installed in PREFIX, make sure PREFIX/bin is in
    *** your path, or set the GTK_CONFIG environment variable to the
    *** full path to gtk-config.
    checking for gtk-config... (cached) no
    checking for GTK - version >= 1.2.3... no
    *** The gtk-config script installed by GTK could not be found
    *** If GTK was installed in PREFIX, make sure PREFIX/bin is in
    *** your path, or set the GTK_CONFIG environment variable to the
    *** full path to gtk-config.
    configure: error:
    The development files for GTK+ were not found. For GTK+ 2, please
    ensure that pkg-config is in the path and that gtk+-2.0.pc is
    installed. For GTK+ 1.2 please check that gtk-config is in the path,
    and that the version is 1.2.3 or above. Also check that the
    libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
    --libs' are in the LD_LIBRARY_PATH or equivalent.

必要なライブラリは以下。

1
# apt install libgtk2.0-dev

OpenGL

エラーメッセージは以下。

    checking for OpenGL headers... not found
    checking for GL/gl.h... no
    configure: error: OpenGL libraries not available

必要なライブラリは以下。

# apt install mesa-common-dev libglu1-mesa-dev

GStreamer

エラーメッセージは以下。

    checking for GST... configure: WARNING: GStreamer 1.0 not available, falling back to 0.10
    checking for GST... configure: WARNING: GStreamer 0.10 not available, falling back to 0.8
    configure: error: GStreamer not available

何故か、GStreamer 1.0 をインストールしても認識されなかったので、GStreamer 0.10 を入れました。

# apt install python-gst0.10-dev

webkit

これはかなりわかりにくかったです。 延々とエラーメッセージが出力されるので、本来のエラーメッセージを探すのが結構手間なのです。

  ../../../sip/cpp/sip_html2cmodule.cpp:386:4: error: 'wxWebView' in namespace '::' does not name a type
    ::wxWebView* sipVH__html2_21(sip_gilstate_t sipGILState, sipVirtErrorHandlerFunc sipErrorHandler, sipSimpleWrapper *sipPySelf, PyObject *sipMethod,  ::wxWindow*parent, ::wxWindowID id,const  ::wxString& url,const  ::wxPoint& pos,const  ::wxSize& size,long style,const  ::wxString& name)
      ^
...以下延々と続く

必要なライブラリは以下。

# apt install libwebkit-dev
  1. もちろん、Docker を使わなくてもインストールは出来るはずです。 
?

2 件のコメント:

nama さんのコメント...

大変参考になりました、助かりました!

Yusuke さんのコメント...

お役に立てたようで何よりです。
wxPython 4.0.1 以降では wheel が用意されて、さらに簡単にインストール可能になりました。
もし良かったら参考にしてください。

Linux に wxPython をインストールする方法