Menu

PyQt4

Featured (9)
Anonymous Bruno Santos

Table of Contents

Note: WCL stands for Windows Command Line in this wiki page.

Introduction

Given the software stack already present in ParaView's installers for Windows, adding PyQt4 to the software stack is a useful toolkit for using along with Python and VTK. Nonetheless, beware to not use PyQt4 directly from within ParaView, since it's very likely to lead to a crash.

This page focuses on Windows only, because these software stacks are usually already available on Linux Distributions and possibly for Mac OS X. Another useful note is that there is another project named Python(x,y) which provides a more complete Python-based software stack; the only issue is that even though it provides VTK and PyQt4, it does not provide ParaView.

Build PyQt4 from source code with MSVC 2008

Requirements

Given that we want to add PyQt4 to the software stack in ParaView 4.1.0, there are 3 requirements we need to build PyQt4:

  1. MSVC 2008 - we'll be using the Express edition:
  2. Python 2.7.3: https://www.python.org/ftp/python/2.7.3/
  3. Qt 4.8.2: https://code.google.com/p/qt-msvc-installer/

This may seem strange that ParaView 4.1.0 itself isn't necessary, but the idea here is that PyQt4 only needs to be built with the same MSVC, Python and Qt versions as ParaView 4.1.0 was built.

Advice: if you need to build both the 32 and 64-bit builds, then install each Python version in separate folders, for example:

C:\Python27\Win32
C:\Python27\Win64

In additon, we'll be assuming on this wiki page that Qt 4.8.2 is installed in the following folders:

C:\Qt\4.8.2
C:\Qt\4.8.2_x64

Prepare the development environment

After installing all of the requirements (don't forget that 32 and/or 64-bit architectures have to be installer mostly separately), begin creating the development environment for building and installing PyQt4:

  1. Download the source code packages for PyQt4 and SIP:
  2. Unpack both in the same folder, for example W:\PyQt4-sandbox
  3. Create a new folder for the installation itself, for example W:\PyQt4-sandbox\PyQt4-Qt4.8.2-Python2.7.3-win64

Now this is a somewhat tricy part, because we have to prepare a Windows Command Line (WCL) environment with all of the necessary tools for building SIP and PyQt4. The instructions will be given in separate subsections:

32-bit Development Environment

First you need to find the batch file that starts up the WCL environment with MSVC 2008 32-bit. For example, at C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin you should be able to find the batch file vcvars32.bat, but more specifically you can find also there the Windows shortcut file Visual Studio 2008 Command Prompt. Double-click on that shortcut file and it will start a new WCL with the necessary MSVC 2008 building tools ready to be used.

Now, in this WCL we need to activate 2 additional environments: Qt and Python. To activate Qt, it should be as simple as running these commands:

cd C:\Qt\4.8.2
call QtVars.bat

Next, to activate Python, run these commands:

cd C:\Python27\Win32
set PYTHONHOME=%CD%
set PATH=%PATH%;%CD%

Now you can move on to the next section: Building SIP

64-bit Development Environment

First you need to find the batch file that starts up the WCL environment with MSVC 2008 64-bit. For example, at C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin you should be able to find the batch file vcvarsx86_amd64.bat, but more specifically you can find also there the Windows shortcut file Visual Studio 2008 x64 Win64 Command Prompt. Double-click on that shortcut file and it will start a new WCL with the necessary MSVC 2008 x64 building tools ready to be used.

Now, in this WCL we need to activate 2 additional environments: Qt and Python. To activate Qt, it should be as simple as running these commands:

cd C:\Qt\4.8.2_x64
call QtVars.bat

Next, to activate Python, run these commands:

cd C:\Python27\Win64
set PYTHONHOME=%CD%
set PATH=%PATH%;%CD%

Now you can move on to the next section: Building SIP

Building SIP

With the WCL ready to use MSVC, Qt and Python, we now need to build SIP, which is needed for later building PyQt4. In theory, it should be as simple as running the following commands (this is an example for 64-bit):

set PYQT4_PATH=W:\PyQt4-sandbox\PyQt4-Qt4.8.2-Python2.7.3-win64

cd /d w:\PyQt4-sandbox\sip-4.16.2

python configure.py --bindir %PYQT4_PATH%\bin --destdir %PYQT4_PATH%\Lib\site-packages --incdir %PYQT4_PATH%\include --sipdir %PYQT4_PATH%\Lib\sip --platform win32-msvc2008
nmake
nmake install

set PATH=%PATH%;%PYQT4_PATH%\bin

Note: The platform option is the same win32-msvc2008 for both 32 and 64-bit.

Now you can move on to the next section, namely Building PyQt4.

Building PyQt4

The next steps assume you've followed the previous sections. In addition, if you need to perform 2 builds, one per architecture, it's best to use different source code folders for each build.

The following commands should do the trick:

cd W:\PyQt4-sandbox\PyQt-win-gpl-4.11.1

python configure-ng.py --confirm-license --bindir %PYQT4_PATH%\bin --destdir %PYQT4_PATH%\Lib\site-packages --sip-incdir %PYQT4_PATH%\include --sipdir %PYQT4_PATH%\Lib\sip --no-designer-plugin

set CL= /MP
nmake release
nmake install

Note: The option --no-designer-plugin was necessary because the debug version of Python was not used.

Packaging PyQt4

There are two main steps to quickly packaging:

  1. Add a batch file that helps you set-up the WCL where you install PyQt4 later on, as explained in section Batch file for loading PyQt4 to WCL environment.
  2. Compress the installation folder, for example, as explained in the section Create self-extractable with 7zip.

Batch file for loading PyQt4 to WCL environment

Create a file named PyQt4env.bat in the main folder for the installation of PyQt4, for example, in W:\PyQt4-sandbox\PyQt4-Qt4.8.2-Python2.7.3-win64, with the following content:

set PYTHONPATH=%~dp0Lib\site-packages;%PYTHONPATH%
set PATH=%PATH%;%~dp0bin

Now, you can call this batch file from whatever batch file that activates your WCL environment, for example, by running:

call P:\PyQt4-Qt4.8.2-Python2.7.3-win64\PyQt4env.bat

Create self-extractable with 7zip

You can either do it interactively through Windows Explorer (right-click on the folder and compress), or you can use the following command, from within the sandbox folder where the installation was made:

7z a -sfx -t7z -mx=9 -ms=on -mmt=on PyQt4-Qt4.8.2-Python2.7.3-win32-r1.exe PyQt4-Qt4.8.2-Python2.7.3-win32
7z a -sfx -t7z -mx=9 -ms=on -mmt=on PyQt4-Qt4.8.2-Python2.7.3-win64-r1.exe PyQt4-Qt4.8.2-Python2.7.3-win64

Installation

There are several ways that this can now be installed:

  1. You can place the contents of the folder PyQt4-Qt4.8.2-Python2.7.3-win* directly inside the main folder of where Python 2.7.3 is installed, so that the folder Lib\site-packages\PyQt4 is placed at Python's Lib\site-packages folder.
  2. Or you can integrate with ParaView's installation, by placing the contents of the folder PyQt4-Qt4.8.2-Python2.7.3-win*\Lib\site-packages inside ParaView's folder ParaView-4.1.0\lib\ParaView-4.1\site-packages or inside the folder ParaView-4.1.0\bin\Lib\site-packages.
  3. Or you can integrate directly with some other Python based library or toolkit, by overlapping the folders as exemplified in the previous two points.

Available builds

Windows


Related

Wiki: FrontPage
Wiki: PyQt4

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.