< Getting Started‎ | Build‎ | KDE4
Revision as of 12:13, 25 October 2008 by Pippin (talk | contribs) (→‎Longer instructions: Add note about python-dbus)

Getting Started/Build/KDE4/Python Support

Note: This page refers to building and installing KDE Python support from KDE subversion trunk during the KDE 4.2 development cycle and may not apply to other versions of KDE. (Situation from 23 October 2008)

Installing Python bindings and support directly from KDE trunk in subversion is a little bit tricky, mainly due to the stack of dependencies which need to be built up first.

Please note that most of the time there is little reason to install and run the Python bindings and support directly from subversion. If you are an application developer then just use the packages from your distribution. Running from subversion generally doesn't get you early access to new functionality in kdelibs etc because the bindings are only updated around the end of KDE's development cycle. That being said, running from subversion will get you access to the new Python support in Plasma and also the new bindings for Marble.

Short instructions

  • Install and setup KDE from subversion.
  • Build everything needed up to and including kdelibs.
  • Install Python into your kde svn install directory.
  • Install SIP. (use a snapshot from Riverbank)
  • Install PyQt4. (use a snapshot from Riverbank)

Longer instructions

First step, get your KDE subversion install / environment setup and build and install kdelibs.

The standard Python interpreter has a site-packages directory inside its installation directory which is where system wide Python modules are installed. This is how Python finds modules when you import them in your program. Unfortunately Python traditionally does not have a per-user site-packages directory where private copies of modules can be installed, although I believe support for this has been added in the new 2.6 release. This means to we need our own Python installation into which we can install PyQt, PyKDE and friends.

Download and install a new Python 2.5 ("Other platforms" -> "bzip2-compressed source") into the same install prefix as your KDE trunk install. After building and installation, the new python should be the first one on your $PATH. Make sure you build Python with shared libraries enabled. "./configure --prefix=/home/kde-devel/kde --enable-shared" seems to be sufficient, although you might want more options and do not forget to change your install prefix.

You may want to install dbus-python at this point to allow Python scripts to access D-Bus.

A couple of important bugs have been fixed in SIP. Grab the SIP snapshot from Riverbank Computing and unpack the archive somewhere. Running "python configure.py", answering 'yes' or something and then letting run, and then running "make" and "make install" should be enough to get it installed.

Grab a PyQt4 snapshot from Riverbank Computing and do the same things a SIP to build and install it. A snapshot is needed to fix at least one bug which affects Plasma.

With those dependencies in place building kdebindings is a matter of checking out the code and running your 'cmakekde' command. It should then find Python, build and install.

Now you have a working PyKDE4 install which supports kdelibs and a whole bunch of other related libraries like soprano, nepomuk etc.

Now you can check out and build kdebase. It should detect the KDE Python support and automatically build the Python script engine.

Creating and Installing Python Plasmoids

In order to create and install an applet written using the Python scriptengine, you package it into a specially crafted zip file and install it using the "plasmapkg" tool, which should come with your plasma from kdebase.

The directorystructure looks as follows


To create the package zip the directory recursively.

$ cd py-applet/
$ zip -r ../py-applet.zip .

(Don't create the zip file inside the directory you're zipping.)

Then install the created plasma package with

$ plasmapkg -i py-applet.zip

You can remove it using

$ plasmapkg -r py-applet

Metadata in the .desktop File

The metadata for your applet is specified in the .desktop File. Here's an example of the python clock applet.

[Desktop Entry]
Name=Python Clock

X-KDE-PluginInfo-Author=Simon Edwards
[email protected]

The X-Plasma-API string specifies that the applet uses the python scriptengine.

This page was last edited on 21 November 2008, at 21:13. Content is available under Creative Commons License SA 4.0 unless otherwise noted.