[[labs.beatcraft.com]]~
[[OS X]]~
[[Python]]~

#Contents

* PyQt5 on MacOS X Mavericks [#b7d83d13]
>
This article introduces PyQt and explains how to install PyQt5 on Mac OS X Mavericks 10.9.5. This shows how to build Qt for OS X and bind to Python with PyQt.~

** About PyQt [#w58bbca2]
>
PyQt is one of GUI programming tools for Python. Specifically, PyQt is a Python binding for Qt, which is a cross platform GUI kit. There are several Python GUI programming tools: PySide, PyGTK, wxPython, Tkinter, and others.~
~
PyQt is developed by Riverbank Computing Ltd, and it offers two different types of software licences. One is for GPL, and the other is a usual commercial license. PyQt is a cross platform tool kit, so it supports Windows, Linux, and OS X. For the details of PyQt as well as Riverbank Ltd and/or download a copy of PyQt, please visit the URL below.~

** Installing Environment [#da64967a]
>
The hardware, which is used for this article, is a late 2012 model, and Mac OS X Mavericks 10.9.5.~
 $ sw_vers
 ProductName:  Mac OS X
 ProductVersion:  10.9.5
 BuildVersion:  13F34
~
The version of Xcode is 6.0.1~
 $ xcode-select -p
 /Applications/Xcode.app/Contents/Developer
 $ xcodebuild -version
 Xcode 6.0.1
 Build version 6A317

** Installing Qt [#ub0a8b50]
>
Installing Qt, first. The version of Qt used here is 5.3.2. We have tried to download Qt Online Installer for OS X (qt-opemsource-mac-x64-1.6.0-5-online.dmg) and to install Qt.~
[[http://www.qt.io/download/]]~
~
However, as the installer did not support OS X 10.9.5 at that time, QtCreater did not work. Thus, Qt should be built from its source code and instal it.~
~
Please download the source code from the URL listed below. Qt's web page has been changed, and it is very difficult to navigate and to find the source code. Please try the URL below.~
[[http://download.qt-project.org/official_releases/qt/5.3/5.3.2/single/qt-everywhere-opensource-src-5.3.2.tar.gz]]~
~
Expand the file, move to the expanded file, and execute configure. There are no options for config. It remains as the default.~
~
 $ 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...
 ........ Skip
~

>
While executing configure, the script will ask several questions about the edition and license of your Qt. This Q-A session acts as a config option, so please input your answers, properly. Eventually, Makefile shown below is created with config option.~
~
 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.
~

>
Then, using makefile, build and install Qt. (To build Qt, Mac mini needs a few hours.)~
~
 $ make
 $ sudo make install
~
As it is shown in Makefile, Qt is installed in the directory of /usr/local/qt-5.32.~

** Installing SIP [#ba91f85f]
>
To install PyQt,  you have to install SIP. SIP is developed and available at the developer of PyQt, Riverbank Computing Ltd. SIP is written in C/C++, and it is a tool that enables to create the Python library easily. This article uses the version of 4.16.3.~
~
- SIP Download page~
[[http://www.riverbankcomputing.com/software/sip/download]]~
~
Please download SIP 4.16.3 from the URL below.~
[[http://sourceforge.net/projects/pyqt/files/sip/sip-4.16.3/sip-4.16.3.tar.gz]]~

>
Expand the downloaded file, and move to it. Using configure, create Makefile. Using Makefile, build and install SIP.~
~
 $ 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
~
SIP is installed to the directory where configure indicates as PATH. Please remember or note PATH, which is needed when Qt is installed.~

** Installing PyQt [#ka2ba8d4]
>
Since all requirements for PyQt have been installed, PyQt is being installed. In this article, PyQt 5.3.2 is used. The version of PyQt is matched to the version of corresponding Qt, ~
~
-PyQt Download page~
[[http://www.riverbankcomputing.com/software/pyqt/download5]]~
~
Please download PyQt from the URL~
[[http://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.3.2/PyQt-gpl-5.3.2.tar.gz]]~

>
Expand the archive of the source code. Move to the directory of the expanded archive.~
~
 $ tar xvf PyQt-gpl-5.3.2.tar.gz
 $ cd PyQt-gpl-5.3.2
~
To apply diff command, modify config.py before execute configure command.  Without this modification, an error occurs when it builds WebKitWidgets. There is a difference in the context. The detail is shown in the code below.~
 $ 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']),

>
As the modification is completed, execute the configure command with options shown below. Then, built and install PyQt.~
~
 $ 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
~
PyQt is installed at the directory of /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages.~

** Execute PyQt examples. [#g9f8a06b]
>
Completing the installation of PyQt, test whether PyQt is installed correctly or not. To examine its correct installation, execute examples, which are stored in PyQt source code archive. If these samples work well, the installation of PyQt is successful.~
~
Configure PYTHONPATH as it shown below, and execute qtdemo of samples.~
~
 $ 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
~
Starting up the GUI application, the application window like the screen shot below, appears. Please select one of the samples from the menu. If the selected one works well, PyQt is successfully installed.~
#ref(pyqt_examples_gui.png,,70%)~
#ref(pyqt_examples_gui.png,,60%)~

* Revision History [#c6c9eb4c]
>
>- 2014/12/25 This article is initially uploaded

Front page   Edit Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   RSS of recent changes