2017/04/25

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

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

今回は様々な依存関係を断つために、Docker 上にインストールしてみましたもちろん、Docker を使わなくてもインストールは出来るはずです。。
Docker 便利だなー。



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

```text
`highlight: 4;
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
```

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

- [Docker で GUI アプリケーションを実行する方法 | 穀風](https://kokufu.blogspot.jp/2017/02/docker-gui.html)

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

```python
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. ``` 必要なライブラリは以下。 ```console # apt install libgtk2.0-dev ``` ### OpenGL エラーメッセージは以下。 ``` checking for OpenGL headers... not found checking for GL/gl.h... no configure: error: OpenGL libraries not available ``` 必要なライブラリは以下。 ```console `gutter: false; # 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 を入れました。 ```console `gutter: false; # 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) ^ ...以下延々と続く ``` 必要なライブラリは以下。 ```console `gutter:false; # apt install libwebkit-dev ```

0 件のコメント: