[SailfishDevel] Python & Qt5 (PyOtherSide / PyQt)

Thomas Perl th.perl at gmail.com
Mon Sep 30 12:40:23 UTC 2013


Hi,

On Sep 30, 2013, at 1:08 PM, Matt Austin <mail at mattaustin.me.uk> wrote:
> It looks like we might now have a couple of possible options with Python apps on Sailfish with Qt5:
> 
> 1) PyOtherSide: http://thp.io/2011/pyotherside/
> 
> 2) PyQt 5.0.1: http://www.riverbankcomputing.com/news/pyqt-501
> 
> I've been playing around today, and unfortunately was unable to get either installed nicely on the Sailfish VM. PyOtherSide requires Python 3 (which as far as I can tell is not available in the Sailfish VM), and I thought I managed to get PyQt to make/install, but then I just got symbol errors when I tried to import the modules.
> 
> Obviously I'm not very good at compilation/linking/dependencies/flags/headers etc. (I am a python user after all :P ). So I was wondering if there are any plans to add either PyOtherSide or PyQt5 to the sailfish repos?


I can't say too much about PyQt, as I haven't used it myself. For PyQt, you might have to package it yourself, but be aware of PyQt's licensing: http://www.riverbankcomputing.com/software/pyqt/license

The rest of this mail deals with PyOtherSide:

It's available in the mer-python3 repository:
https://build.merproject.org/project/show?project=mer-python3

In the sb2 target and on a device, you can add that repo using:
zypper ar http://repo.merproject.org/obs/mer-python3/latest_armv7hl/mer-python3.repo

In the Emulator, you can add that repo using:
zypper ar http://repo.merproject.org/obs/mer-python3/latest_i486/mer-python3.repo

After that (and a possible "zypper ref"), you can install the QML Plugin in the emulator using:
zypper in pyotherside-qml-plugin-python3-qt5

If you are packaging an application, you should also add this to the RPM .spec file (as QML dependencies are not auto-detected):
Requires: pyotherside-qml-plugin-python3-qt5

Be aware that this is a run-time dependency, so you don't really need to install the QML plugin in your SDK target (it doesn't need to be available at build-time), only on the emulator and on the device where you actually run the application.

The sources are available here:
https://github.com/mer-python3/

The API documentation is here:
http://thp.io/2011/pyotherside/doc/classQPython.html

Some basic usage examples are here:
https://github.com/thp/pyotherside/tree/master/examples

If you're coming from PySide on Harmattan, it's a totally different setup -- instead of launching a Python interpreter that then loads the PySide bindings, which then resolve all Qt symbols that have bindings (takes a long time), you start out with a normal QML application (startup speed = same as C++ QML application) and then import the PyOtherSide QML plugin there (only loads libpython), and once the UI is up (i.e. the user can see your application window), you can then start loading Python modules, etc..

Also, try to avoid the synchronous functions, and use the asynchronous API instead (see PyOtherSide's documentation for examples). Think of your Python code as the "data backend implementation" for your QML UI, and think of your QML code as your main application. Or in other words, "QML uses the services of Python for its backend", instead of "Python uses the services of QML for its frontend".

Also, it's Python >= 3.3 only at this point. See http://www.python.org/dev/peps/pep-0404/ and https://github.com/thp/python2sucks to figure out why this is a very good idea and why you want to have that.

Protip: If you want to have a Python 3 interpreter to play with on the command line, install "python3-base" from that repository.


HTH :)
Thomas


More information about the Devel mailing list