On Windows, we first need to install the pre-compiled Qt binary package from the Trolltech downloads page. Select the LGPL/Free tab and choose the “Qt SDK: Complete Development Environment” for Windows. It is a fairly hefty package (167 megabytes) and may take a while to transfer. The installer includes the core Qt libraries, several important C++ development tools, and an integrated development environment (IDE) called Qt creator. Luckily, the same installer will work on Windows XP, Windows Vista and Windows 7.

Qt and MinGW

When you run the installer, it will ask for the installation destination. To avoid future problems, this folder should not include any spaces. The default is “C:\Qt\2009.02”, but because I like to keep the root directory of my drive as clean as possible, I changed this to “C:\Qt\Windows”. To begin the installation, press “Install.”

The installer will also download and configure the GNU compiler toolset for Windows (also known as MinGW). By default, MinGW will be installed in a subdirectory under the main Qt directory. In this example, it was installed to “C:\WINDOWS\Qt\mingw”. Note this file path, it will be important to the steps below.

Python

After you finish with the Qt framework, the next step is to download and install Python. You can get the Python interpreter and other associated files from the Python release download page. While the newest version is Python 3.0.1, I would recommend that you download and install Python 2.5.4 instead. When trying to set up SIP with Python 2.6.2 and Python 3.0.1, I experienced a number of errors. These were resolved by using the x86 version of Python 2.5.

When you first run the installer, it will ask whether you want to install Python for all users or for just the current users. Make sure that “install for all users” is selected. Like Qt, you should install Python to a directory without spaces. The default install location will be “C:\Python25”, though I typically change it to “C:\Windows\Python25” so that it matches the installation directory for Qt.

After the Python installer has finished running, you will need to modify one of the Windows environment variables. On Windows XP, the easiest way to access the environment variables to right click on “My Computer” and select “Properties” from the drop own menu. When the “System Properties” window launches click on the “Advanced” tab and then press the “Environment Variables” button. (If you are using Windows Vista or the Windows 7 beta, the easiest way to access the Environment Variables is to go to Control Panel and Search for “Path” in the search bar. All other steps remain the same.)

From the “System Variables” list, select the Path Variable and then press “Edit”.

In the variable value box, type in the path to the Python folder you just installed, the path to the “bin” folder of MinGW (which should be under the MinGW folder from above), and last the path to a Qt program called qmake (which is located in the qt\bin folder of the Qt installation) . You should separate these values from the other paths (and from each other) by a semi-colon. If you have followed all of the instructions in this tutorial, you will add:

Press “Ok” to close the dialog box and then “Ok” again to close first the Environment Variables and then the “System Properties Pane.” Now that you have changed the Path variable, you need to restart your computer so that the changes can take effect.

SIP and PyQt

Prior to compiling PyQt, you will first need to compile and install SIP, which can be found at Riverbank Software. Though the stable version of the software is currently (4.7.9), you will need to download the latest Windows source code snapshot of version 4.8 (Qt 4.5 doesn’t work with earlier versions of SIP). (Update: Alternatively, you can also find a copy of the 4.8 snapshot here.) You will need the most recent source code snapshot of PyQt 4.5, which is also available from Riverbank. (Update: Multiple people seem to have had problems installing the 4.5 snapshot from the Riverbank website. As a matter of convenience, you can find the April 30, 2009 version here. This is the same version that was used in the writing of this article.)

After you have finished downloading the source files, extract them to the Q
t installation directory (C:\Windows\Qt in this tutorial). This might also be a good time to rename the directories to something shorter than the default snapshot names. I have changed mine to PyQt4 and sip-4.8.

The rest of the steps will be run from the command line prompt (cmd.exe) and must be run with administrator privileges to work properly. Start by going to the start menu and then choosing the run command; then type “cmd.exe” and press enter. (If you are on Windows Vista, you can open the command prompt by typing “cmd.exe” in the search dialog of the start menu. To run with administrator privileges, right click on the top program choice and select “Run as administrator” from the context menu.)

At the command line, first, go to the Qt installation directory by typing:

cd C:\Windows\Qt

Then go to the SIP directory:

cd sip-4.8

Prior to compiling, we need to create a proper configuration file:

python configure.py –p win32-g++

After the configuration is done, compile the new file by typing:

mingw32-make

This will take some time. After the files have finished compiling, you can install them by typing:

mingw32-make install

The process is repeated for PyQt. Change to the PyQt4 source directory by typing:

cd .. cd PyQt4

Then configure the make files, compile and install by typing:

python configure.py –p win32-g++ mingw32-make mingw32-make install

Since Qt is a rather large framework, it may take between 15 and 30 minutes to fully compile.

Update: If you only want to run PyQt programs, the installation process can be greatly simplified by using the automated PyQt installer for Windows. The installer will automatically install a copy of the Qt framework and the PyQt bindings. You will need to install Python separately, however.

Comments

15 Responses to “Installation of PyQt on Windows”

Jason
wrote a comment on May 31, 2009

Thank you. Nice article which is easy to follow.

Still, I ran into an issue…

At the current time, there are no SIP 4.8 snapshots available on the Riverbank website. I found one through GitHub at:http://github.com/kevinw/sip/tree/master
by using the download button and choosing (.zip) for Windows, but the process failed at the make command. I then tried the stable 4.7.9 release and the make command was successful, but the install failed.

If you have a copy of the snapshot, could you provide a link to download it, or send a copy to my email?

Thanks. In the meantime, I will keep an eye on the Riverbank download page.

@Jason. You happen to be in luck, for I do have a copy of the sip48 snapshot code. I can’t remember which version it is, but it successfully compiled and installed without issue. It is also the same version which I used to compile and install the PyQt snapshot.

If you are Windows Vista or Windows 7, make sure that you run all commands as an administrator. (Or if you are using XP, make sure that the commands are run from an administrator account.) I have verified that you can build and install this version of SIP on Windows XP, Windows Vista, and the release candidate of Windows 7.

Jason
wrote a comment on June 1, 2009

Maybe you also have the PyQt 4.5 snapshot by chance? I can find the Windows snapshot on the Riverbank website, but it doesn’t seem to compile correctly. I have found one other user with the same issue in their mailing list (http://www.riverbankcomputing.com/pipermail/pyqt/2009-June/023134.html), but was posted just recently, so who knows if/when the issue will be resolved… It is annoying that Riverbank doesn’t keep a short history of snapshots available.

I spent a bit of time playing with other configurations early this event. In the process, I experimented with different versions of Python. For reasons I don’t understand, I had issues with Python 2.5.4. (Though it worked flawlessly for me the first time I set up PyQt.) In a virtual machine with a clean Windows XP SP3 install, I was successfully able to compile and install with the most recent version of Python 2.6. However, your mileage may vary.

Regis
wrote a comment on June 3, 2009

I appreciate this how-to. I followed these instructions and didn’t appear to have an hitches with the installation. However, when trying to run “from PyQt4.QtCore import *” I receive the following error:
File “”, line 1, in
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

I’m running XP sp2 and have tried both Python 2.5 and 2.6.

Anyone else have this problem? Anyone have any luck solving it?

Thanks,
Regis

Regis
wrote a comment on June 3, 2009

Did a did a complete uninstall and then reinstall of everything and this is what I finally got to work.

The first time around I installed everything under C:. The second time, I followed these instructions verbatim and installed to C:\Windows. I don’t know if that really made a difference, but at least everything is working for me now. Thanks again for the post.

Regis

arik181
wrote a comment on June 5, 2009

Lucid and useful. Thanks.

Kittisak
wrote a comment on June 10, 2009

Hello, thank you for your tutorial.
I follow it and can install all successfully but when i try to run ‘from PyQt4 import QtCore’ i get windows dialog error, it tell me:

pythonw.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

First installation, i separate Qt folder and Python folder (PyQt4 and sip48 is in Qt folder) i get error, so i uninstall all of it and reinstall again by,
i create folder c:\Python_Qt then put both Qt and Python in this folder but it still show same error.

I MUST use C:\Windows folder same as you, right?
or something that i don’t know?

@notize: At the moment (and quite unfortunately), yes. But I hope to change that in the very, very near future. I am in the process of creating a stand-alone installer which has only the things necessary for Time Drive to run (Duplicity, PyQt, etc). I’m nearly there but I’ve never done an installer before and want to test it before I break anyone’s machine. I will post a blog post about it as soon as it is ready.

I’m also waiting until the next iteration (0.2) is done and tested because it will support browsing and restoring older snapshots and clean up a few little things that don’t quite work right, yet. The joys of young software, it still has all the sharp edges.

Walter Behrnes
wrote a comment on September 16, 2009

Hi, I ran through the tutorial and ran into a snag at the very end.
When I try to run

[…] While the process is identical, however, the particulars are a little more involved. Luckily, they are topics that I’ve written about before. For a guide to installing Qt and Qt creator on Mac, take a look at this post. For Windows, instructions can be found here. […]

John McCabe
wrote a comment on August 9, 2010

Hi

I’m just interested in knowing why there’s any specific reason why you’d need to install PyQt and SIP within the Qt folder hierarchy.

John

Sergio
wrote a comment on April 12, 2011

Hello,

I am following the tutorial and everything went smoothly until the command “mingw32-make” in the command line. The error I’m getting is :
“mingw32-make ” is not recognized as an internal or external command, operable program or batch file.

Am I missing something? I installed the Qt SDK, then both PyQt 4.12.2 snapshot and Sip 4.12.2 snapshot as well all in the Qt directory as instructed..

You’re getting that error because the mingw binary (/bin/) didn’t get added to your path variable correctly. I’m not currently at a Windows machine, so I can’t give you step by step instructions, but here’s the general picture of what you need to do.

1.) Find the mingw32-make.exe file. If you installed the Qt SDK, it should be one of the Qt sub-directories.
2.) Once you locate the directory, open up the “User Variables” from the control panel. (Instructions for doing so can be found in the article.
3.) Add the Qt sub-directory to the list.
4.) Open up a new command line shell and resume the installation.

Cheers,

Rob

Care to comment?

Name (required)

Mail (will not be published) (required)

Website

Wordpress Hashcash needs javascript to work, but your browser has javascript disabled. Your comment will be queued in Akismet!