English French [qt-devnet.developpez.com]

Building PySide on Linux

PySide uses CMake’s system to build the source code packages. You can familiarize yourself with CMake at PySide_CMake_Primer.

The Easy Way

There is now a “BuildScripts” repository available on GitHub:

https://github.com/PySide/BuildScripts

With this repository, you can automate the build steps outlined in this Wiki page. It also takes care of installing the correct prerequisite packages for your distribution (i.e. use sudo ./dependencies.ubuntu.sh to install build dependencies on Debian or Ubuntu). If there is no dependencies script for your distribution, please submit a patch. See the README [github.com] file for detailed usage instructions.

Prerequisites

  • CMake >= 2.6.0
  • Qt libraries and development headers >= 4.6 (preferably the latest stable release)
  • libxml2 and development headers >= 2.6.32 (for apiextractor only)
  • libxslt and development headers >= 1.1.19 (for apiextractor only)
  • Python libraries and development headers >= 2.5 (for shiboken and pyside)

Overview

PySide consists of a chain of four interdependent packages:

  1. The API Extractor library is used by the bindings generator to parse the header and typesystem files to create an internal representation of the API. It is based on the QtScriptGenerator [labs.trolltech.com] codebase.
  2. The Generator Runner (A.K.A. generatorrunner) is the program that controls the bindings generation process according to the rules given by the user through headers, typesystem files and generator front-ends (such as Shiboken Generator). It depends on API Extractor library.
  3. The Shiboken Generator (A.K.A. shiboken) is the plugin that creates the PySide bindings source files from Qt headers and auxiliary files (typesystems, global.h and glue files). It depends on Generator Runner and API Extractor library.
  4. PySide Qt bindings (A.K.A. pyside) is the set of typesystem definitions and glue code that allows generation of Python Qt binding modules using the PySide toolchain. It depends on the Shiboken libraries and Generator Runner.

There is also an optional package called pyside-tools which provides some useful utilities for creating PySide applications. If you don’t want or need that package, skip the commands that say “pyside-tools” in them in the scripts below.

Getting the source code

The source code for the current stable release can be downloaded from PySideDownloads.

Alternatively, you can get the latest development branch from the repos:

  1. git clone git://gitorious.org/pyside/apiextractor.git
  2. git clone git://gitorious.org/pyside/generatorrunner.git
  3. git clone git://gitorious.org/pyside/shiboken.git
  4. git clone git://gitorious.org/pyside/pyside.git
  5. git clone git://gitorious.org/pyside/pyside-tools.git

Building and installing

Sandbox

If you wish to install PySide into a local sandbox then follow these instructions, otherwise you can skip this step.

We will assume that PYSIDESANDBOXPATH will be the path to your local sandbox.

  1. export PYSIDESANDBOXPATH=$HOME/sandbox

Setup these variables accordingly.

  1. export PATH=$PYSIDESANDBOXPATH/bin:$PATH
  2. export PYTHONPATH=$PYSIDESANDBOXPATH/lib/python2.6/site-packages:$PYTHONPATH
  3. export LD_LIBRARY_PATH=$PYSIDESANDBOXPATH/lib:$LD_LIBRARY_PATH
  4. export PKG_CONFIG_PATH=$PYSIDESANDBOXPATH/lib/pkgconfig:$PKG_CONFIG_PATH
  5. # set -DENABLE_ICECC=1 if you're using the icecream distributed compiler
  6. alias runcmake='cmake .. -DCMAKE_INSTALL_PREFIX=$PYSIDESANDBOXPATH -DCMAKE_BUILD_TYPE=Debug -DENABLE_ICECC=0'

It makes sense to place these variables in a shell script that you can reference whenever you need to work with the PySide bindings from the sandbox (especially if you have a system-wide installation of PySide as well).

In the next step replace cmake with runcmake, and sudo make install.

Building

For each package in order (apiextractor, generatorrunner, shiboken, pyside), run the following commands:

  1. mkdir build
  2. cd build
  3. cmake ..
  4. make
  5. sudo make install

Depending on the package and whether there is an existing library with the same version number already installed, you might need to run ldconfig to update the run-time linker cache.

  1. sudo ldconfig

That’s it! PySide should now be successfully built!

Practical tips

Use build scripts for a successful life

Especially if you are just interested in tracking the PySide head, you might be interested in using the following utility scripts.

clone_all:

  1. #!/usr/bin/env bash
  2.  
  3. allrepos="apiextractor generatorrunner shiboken pyside pyside-mobility"
  4.  
  5. for repo in ${allrepos} ; do
  6.     git clone git://gitorious.org/pyside/$repo.git
  7. done

pull_all:

  1. #!/usr/bin/env bash
  2.  
  3. alldirs=("apiextractor" "generatorrunner" "shiboken" "pyside" "pyside-mobility")
  4.  
  5. if [ $# == 0 ] ; then
  6.     dirs=("${alldirs[@]}")
  7. else
  8.     dirs=("$@")
  9. fi
  10.  
  11. for d in "${dirs[@]}" ; do
  12.     (cd "$d"
  13.     git pull origin master
  14.     ) # exit from "$d"
  15. done

build_all:

  1. #!/usr/bin/env bash
  2.  
  3. alldirs=("apiextractor" "generatorrunner" "shiboken" "pyside")
  4.  
  5. if [ $# == 0 ] ; then
  6.     dirs=("${alldirs[@]}")
  7. else
  8.     dirs=("$@")
  9. fi
  10.  
  11. for d in "${dirs[@]}" ; do
  12.     rm -rf "$d/build"
  13.     mkdir -p "$d/build"
  14.     (cd "$d/build"
  15.     cmake ..  && make -j4 && sudo make install || exit 1
  16.     ) # exit from "$d/build"
  17. done

Categories: