Python

MacOS X Mavericks で PyQt を動作させる手順です。

PyQt とは

PyQt は、クロスプラットフォームの GUI ツールキットである Qt の Python バインディングで、
Python で GUI プログラミングをするときの選択肢の一つです。
(PyQt の他には PySide、PyGTK、wxPython、Tkinter などの Python GUI ツールキットが存在します。)
PyQt はイギリス Riverbank Computing によって開発されており、GPL と 商用ライセンスで提供されています。
PyQt はクロスプラットフォームなツールキットであり、Windows、Linux、OS X などをサポートしています。
http://www.riverbankcomputing.com/software/pyqt/intro

インストール環境

インストールを行ったマシンは Mac mini (Late 2012) で、

MacOS X Maverikcs は 2014/09/24 時点で最新の更新である 10.9.5、

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.9.5
BuildVersion:	13F34

Xcode は 2014/09/24 時点で最新の更新である 6.0.1

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
$ xcodebuild -version
Xcode 6.0.1
Build version 6A317

です。

Qt のインストール

まず Qt をインストールします。
version は 2014/09/24 時点で最新の 5.3.2 です。
最初は Qt Project のダウンロードページ
http://qt-project.org/downloads
から
Qt Online Installer for MacOS (qt-opensource-mac-x64-1.6.0-5-online.dmg)
をダウンロードしてインストールしましたが、
10.9.5 への対応がまだ出来てないようで同梱の QtCreater が動作しませんでしたので
ソースコードからビルドしてインストールします。

同ページ上で Show Downloads をクリックし、表示されるソースコード
http://download.qt-project.org/official_releases/qt/5.3/5.3.2/single/qt-everywhere-opensource-src-5.3.2.tar.gz
をダウンロードします。

展開し、configure を実行します。config の option は default のままでOKです。

$ tar xvf  qt-everywhere-opensource-src-5.3.2.tar.gz
$ cd qt-everywhere-opensource-src-5.3.2
$ ./configure
+ cd qtbase
+ /Users/otsuka/Downloads/Qt/qt-everywhere-opensource-src-5.3.2/qtbase/configure -top-level
Which edition of Qt do you want to use ?

Type 'c' if you want to use the Commercial Edition.
Type 'o' if you want to use the Open Source Edition.

o


This is the Qt Open Source Edition.

You are licensed to use this software under the terms of
the Lesser GNU General Public License (LGPL) versions 2.1.
You are also licensed to use this software under the terms of
the GNU General Public License (GPL) versions 3.

Type '3' to view the GNU General Public License version 3.
Type 'L' to view the Lesser GNU General Public License version 2.1.
Type 'yes' to accept this license offer.
Type 'no' to decline this license offer.

Do you accept the terms of either license? yes

Creating qmake...
........ 以下略

script の選択肢に入力で回答し実行することで以下のような config option で Makefile が作られます。

Running configuration tests...

   Configure summary

Build type:    macx-clang (x86_64, CPU features: cx16 mmx sse sse2 sse3 ssse3)

Build options:
  Configuration .......... absolute_library_soname accessibility audio-backend avx avx2 build_all c++11 compile_examples concurrent \
                                   corewlan cups debug debug_and_release freetype full-config getaddrinfo getifaddrs harfbuzz iconv ipv6ifname \
                                   large-config largefile medium-config minimal-config nis opengl openssl pcre png precompile_header qpa qpa \
                                   qt_framework reduce_exports release rpath shared small-config sse2 sse3 sse4_1 sse4_2 ssse3 system-zlib
  Build parts ............ libs tools examples
  Mode ................... debug and release; default link: debug
  Using C++11 ............ yes
  Using PCH .............. yes
  Target compiler supports:
    SSE2/SSE3/SSSE3 ...... yes/yes/yes
    SSE4.1/SSE4.2 ........ yes/yes
    AVX/AVX2 ............. yes/yes

Qt modules and options:
  Qt D-Bus ............... no
  Qt Concurrent .......... yes
  Qt GUI ................. yes
  Qt Widgets ............. yes
  Large File ............. yes
  QML debugging .......... yes
  Use system proxies ..... no

Support enabled for:
  Accessibility .......... yes
  ALSA ................... no
  CUPS ................... yes
  Evdev .................. no
  FontConfig ............. no
  FreeType ............... yes (bundled copy)
  Glib ................... no
  GTK theme .............. no
  HarfBuzz ............... yes
  Iconv .................. yes
  ICU .................... no
  Image formats:
    GIF .................. yes (plugin, using bundled copy)
    JPEG ................. yes (plugin, using bundled copy)
    PNG .................. yes (in QtGui, using bundled copy)
  journald ............... no
  mtdev .................. no
  Networking:
    CoreWlan ............. yes
    getaddrinfo .......... yes
    getifaddrs ........... yes
    IPv6 ifname .......... yes
    OpenSSL .............. yes (loading libraries at run-time)
  NIS .................... yes
  OpenGL / OpenVG:
    EGL .................. no
    OpenGL ............... desktop
    OpenVG ............... no
  PCRE ................... yes (bundled copy)
  pkg-config ............. yes
  PulseAudio ............. no
  QPA backends:
    DirectFB ............. no
    EGLFS ................ no
    KMS .................. no
    LinuxFB .............. no
    XCB .................. no
  Session management ..... yes
  SQL drivers:
    DB2 .................. no
    InterBase ............ no
    MySQL ................ no
    OCI .................. no
    ODBC ................. no
    PostgreSQL ........... no
    SQLite 2 ............. no
    SQLite ............... yes (plugin, using bundled copy)
    TDS .................. no
  udev ................... no
  xkbcommon .............. no
  zlib ................... yes (system library) 

Info: creating super cache file /Users/otsuka/Downloads/Qt/qt-everywhere-opensource-src-5.3.2/.qmake.super
Info: creating stash file /Users/otsuka/Downloads/Qt/qt-everywhere-opensource-src-5.3.2/.qmake.stash

Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/Qt-5.3.2

Prior to reconfiguration, make sure you remove any leftovers from
the previous build.

ビルドしインストールします。(ビルドには Mac mini で数時間要します。)

$ make
$ sudo make install

config option の表示にあったように /usr/local/Qt-5.3.2 へインストールされます。

SIP のインストール

PyQt をインストールするためには、PyQt の開発元 Riverbank Computing の SIP が必要です。
SIP は C/C++ で書かれた Python 用拡張ライブラリの作成を容易にするツールです。
version は 2014/09/24 時点で最新の 4.16.3 です。

SIP のダウンロードページ
http://www.riverbankcomputing.com/software/sip/download
から
http://sourceforge.net/projects/pyqt/files/sip/sip-4.16.3/sip-4.16.3.tar.gz
をダウンロードします。
展開して configure を行い、ビルドしてインストールします。

$ tar xvf sip-4.16.3.tar.gz
$ cd sip-4.16.3
$ python configure.py 
This is SIP 4.16.3 for Python 2.7.5 on darwin.
The SIP code generator will be installed in
/System/Library/Frameworks/Python.framework/Versions/2.7/bin.
The sip module will be installed in /Library/Python/2.7/site-packages.
The sip.h header file will be installed in
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7.
The default directory to install .sip files in is
/System/Library/Frameworks/Python.framework/Versions/2.7/share/sip.
Creating siplib/sip.h...
Creating siplib/siplib.c...
Creating siplib/siplib.sbf...
Creating sipconfig.py...
Creating top level Makefile...
Creating sip code generator Makefile...
Creating sip module Makefile...
$ make
$ sudo make install

configure で表示された PATH にインストールされます。
PyQt のインストール時に必要になるので、 sip コマンドのインストールされる PATH を覚えておきます。

PyQt のインストール

上記の手順で必要なものがインストールされたので PyQt をインストールします。
Version は 2014/09/24 時点で最新の 5.3.2 です。
(対応する Qt と version を同じに揃えられているようです。)
PyQt5 のダウンロードページ
http://www.riverbankcomputing.com/software/pyqt/download5
から
http://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.3.2/PyQt-gpl-5.3.2.tar.gz
をダウンロードします。

$ tar xvf PyQt-gpl-5.3.2.tar.gz
$ cd PyQt-gpl-5.3.2

ソースコードアーカイブを展開したら、configure を実行する前に config.py に以下の差分内容の修正を加えます。
(修正を加えないまま configure を実行してビルドすると、WebKitWidgets のビルド時にエラーになります。)

$ diff -u configure.py.orig configure.py
--- configure.py.orig	2014-09-24 16:32:32.000000000 +0900
+++ configure.py	2014-09-24 16:32:49.000000000 +0900
@@ -87,7 +87,7 @@
     'QtSvg':                ModuleMetadata(qmake_QT=['svg']),
     'QtTest':               ModuleMetadata(qmake_QT=['testlib', 'widgets']),
     'QtWebKit':             ModuleMetadata(qmake_QT=['webkit', 'network']),
-    'QtWebKitWidgets':      ModuleMetadata(qmake_QT=['webkitwidgets']),
+    'QtWebKitWidgets':      ModuleMetadata(qmake_QT=['webkitwidgets', 'printsupport']),
     'QtWebSockets':         ModuleMetadata(qmake_QT=['websockets']),
     'QtWidgets':            ModuleMetadata(qmake_QT=['widgets']),
     'QtWinExtras':          ModuleMetadata(qmake_QT=['winextras', 'widgets']),

修正を加えたら、以下のオプションで configure を実行し、ビルドしてインストールします。

$ python configure.py --sip=/System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip 
Querying qmake about your Qt installation...
Determining the details of your Qt installation...
This is the GPL version of PyQt 5.3.2 (licensed under the GNU General Public License) for Python 2.7.5 on darwin.

Type 'L' to view the license.
Type 'yes' to accept the terms of the license.
Type 'no' to decline the terms of the license.

Do you accept the terms of the license? yes
Found the license file pyqt-gpl.sip.
Checking to see if the QtGui module should be built...
Checking to see if the QtHelp module should be built...
Checking to see if the QtMultimedia module should be built...
Checking to see if the QtMultimediaWidgets module should be built...
Checking to see if the QtNetwork module should be built...
Checking to see if the QtOpenGL module should be built...
Checking to see if the QtPrintSupport module should be built...
Checking to see if the QtQml module should be built...
Checking to see if the QtQuick module should be built...
Checking to see if the QtSql module should be built...
Checking to see if the QtSvg module should be built...
Checking to see if the QtTest module should be built...
Checking to see if the QtWebKit module should be built...
Checking to see if the QtWebKitWidgets module should be built...
Checking to see if the QtWidgets module should be built...
Checking to see if the QtXmlPatterns module should be built...
Checking to see if the QtDesigner module should be built...
Checking to see if the QAxContainer module should be built...
Checking to see if the QtDBus module should be built...
Checking to see if the dbus support module should be built...
DBus v1 does not seem to be installed.
Checking to see if the _QOpenGLFunctions_2_0 module should be built...
Checking to see if the QtSensors module should be built...
Checking to see if the QtSerialPort module should be built...
Checking to see if the QtX11Extras module should be built...
Checking to see if the QtBluetooth module should be built...
Checking to see if the QtMacExtras module should be built...
Checking to see if the QtPositioning module should be built...
Checking to see if the QtWinExtras module should be built...
Checking to see if the QtQuickWidgets module should be built...
Checking to see if the QtWebSockets module should be built...
Checking to see if the Enginio module should be built...
Qt v5.3.2 (Open Source) is being used.
The qmake executable is /usr/local/Qt-5.3.2/bin/qmake.
Qt is built as a shared library.
SIP 4.16.3 is being used.
The sip executable is
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip.
These PyQt5 modules will be built: QtCore, QtGui, QtHelp, QtMultimedia,
QtMultimediaWidgets, QtNetwork, QtOpenGL, QtPrintSupport, QtQml, QtQuick,
QtSql, QtSvg, QtTest, QtWebKit, QtWebKitWidgets, QtWidgets, QtXmlPatterns,
QtDesigner, _QOpenGLFunctions_2_0, QtSensors, QtSerialPort, QtBluetooth,
QtMacExtras, QtPositioning, QtQuickWidgets, QtWebSockets, Enginio.
The PyQt5 Python package will be installed in
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages.
PyQt5 is being built with generated docstrings.
PyQt5 is being built with 'protected' redefined as 'public'.
The Designer plugin will be installed in /usr/local/Qt-5.3.2/plugins/designer.
The qmlscene plugin will be installed in /usr/local/Qt-5.3.2/plugins/PyQt5.
The PyQt5 .sip files will be installed in
/System/Library/Frameworks/Python.framework/Versions/2.7/share/sip/PyQt5.
pyuic5, pyrcc5 and pylupdate5 will be installed in
/System/Library/Frameworks/Python.framework/Versions/2.7/bin.
The interpreter used by pyuic5 is pythonw2.7.
Generating the C++ source for the QtCore module...
Embedding sip flags...
Generating the .pro file for the QtCore module...
Generating the Makefile for the QtCore module...
Generating the C++ source for the QtGui module...
Generating the .pro file for the QtGui module...
Generating the Makefile for the QtGui module...
Generating the C++ source for the QtHelp module...
Generating the .pro file for the QtHelp module...
Generating the Makefile for the QtHelp module...
Generating the C++ source for the QtMultimedia module...
Generating the .pro file for the QtMultimedia module...
Generating the Makefile for the QtMultimedia module...
Generating the C++ source for the QtMultimediaWidgets module...
Generating the .pro file for the QtMultimediaWidgets module...
Generating the Makefile for the QtMultimediaWidgets module...
Generating the C++ source for the QtNetwork module...
Generating the .pro file for the QtNetwork module...
Generating the Makefile for the QtNetwork module...
Generating the C++ source for the QtOpenGL module...
Generating the .pro file for the QtOpenGL module...
Generating the Makefile for the QtOpenGL module...
Generating the C++ source for the QtPrintSupport module...
Generating the .pro file for the QtPrintSupport module...
Generating the Makefile for the QtPrintSupport module...
Generating the C++ source for the QtQml module...
Generating the .pro file for the QtQml module...
Generating the Makefile for the QtQml module...
Generating the C++ source for the QtQuick module...
Generating the .pro file for the QtQuick module...
Generating the Makefile for the QtQuick module...
Generating the C++ source for the QtSql module...
Generating the .pro file for the QtSql module...
Generating the Makefile for the QtSql module...
Generating the C++ source for the QtSvg module...
Generating the .pro file for the QtSvg module...
Generating the Makefile for the QtSvg module...
Generating the C++ source for the QtTest module...
Generating the .pro file for the QtTest module...
Generating the Makefile for the QtTest module...
Generating the C++ source for the QtWebKit module...
Generating the .pro file for the QtWebKit module...
Generating the Makefile for the QtWebKit module...
Generating the C++ source for the QtWebKitWidgets module...
Generating the .pro file for the QtWebKitWidgets module...
Generating the Makefile for the QtWebKitWidgets module...
Generating the C++ source for the QtWidgets module...
Generating the .pro file for the QtWidgets module...
Generating the Makefile for the QtWidgets module...
Generating the C++ source for the QtXmlPatterns module...
Generating the .pro file for the QtXmlPatterns module...
Generating the Makefile for the QtXmlPatterns module...
Generating the C++ source for the QtDesigner module...
Generating the .pro file for the QtDesigner module...
Generating the Makefile for the QtDesigner module...
Generating the C++ source for the _QOpenGLFunctions_2_0 module...
Generating the .pro file for the _QOpenGLFunctions_2_0 module...
Generating the Makefile for the _QOpenGLFunctions_2_0 module...
Generating the C++ source for the QtSensors module...
Generating the .pro file for the QtSensors module...
Generating the Makefile for the QtSensors module...
Generating the C++ source for the QtSerialPort module...
Generating the .pro file for the QtSerialPort module...
Generating the Makefile for the QtSerialPort module...
Generating the C++ source for the QtBluetooth module...
Generating the .pro file for the QtBluetooth module...
Generating the Makefile for the QtBluetooth module...
Generating the C++ source for the QtMacExtras module...
Generating the .pro file for the QtMacExtras module...
Generating the Makefile for the QtMacExtras module...
Generating the C++ source for the QtPositioning module...
Generating the .pro file for the QtPositioning module...
Generating the Makefile for the QtPositioning module...
Generating the C++ source for the QtQuickWidgets module...
Generating the .pro file for the QtQuickWidgets module...
Generating the Makefile for the QtQuickWidgets module...
Generating the C++ source for the QtWebSockets module...
Generating the .pro file for the QtWebSockets module...
Generating the Makefile for the QtWebSockets module...
Generating the C++ source for the Enginio module...
Generating the .pro file for the Enginio module...
Generating the Makefile for the Enginio module...
Generating the C++ source for the Qt module...
Generating the .pro file for the Qt module...
Generating the Makefile for the Qt module...
Generating the .pro file for pylupdate5...
Generating the Makefile for pylupdate5...
Generating the .pro file for pyrcc5...
Generating the Makefile for pyrcc5...
Generating the pyuic5 wrapper...
Generating the Qt Designer plugin .pro file...
Generating the Qt Designer plugin Makefile...
Generating the qmlscene plugin .pro file...
Generating the qmlscene plugin Makefile...
Re-writing
/Users/otsuka/Downloads/Qt/PyQt-gpl-5.3.2/examples/quick/tutorials/extending/chapter6-plugins/Charts/qmldir...
Generating the top-level .pro file...
Making the pyuic5 wrapper executable...
Generating the top-level Makefile...
Satoshi-no-Mac-mini:PyQt-gpl-5.3.2 otsuka$ 

$ make
$ sudo make install

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
にインストールされます。

PyQt examples の実行

インストールが完了したので、PyQt のソースコードアーカイブ内にある examples が
正常に動作するか確認します。
以下のように PYTHONPATH を設定し、examples の qtdemo を実行します。

$ export set PYTHONPATH=$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
$ cd PyQt-gpl-5.3.2/examples/qtdemo
$ python qtdemo.py

以下のスクリーンショットのような GUI アプリケーションが起動しますので、
メニューから呼び出せる機能を実行できれば OK です。


BC::labsへの質問は、bc9-dev @ googlegroups.com までお願い致します。
トップ   新規 一覧 単語検索 最終更新   最終更新のRSS