Update 1/10/2008: PyQt has made the install process a lot simpler because it has bundled everything you need in one installer including QT 4.3 open source edition. Now all you need to do is install Python and the PyQt bundle. Immediately following are the updated steps. Below that is the old instructions.
Update 7/1/2008: Updated for PyQt 4.4.2
NEW INSTRUCTIONS
Here are the steps to install and create a simple "Hello World" GUI application using PyQt 4.4, and Python 2.5, on Windows.
Install Python 2.5
- Go to http://www.python.org/download/ and click on "Python 2.5.x Windows installer"
- Save and run the Windows installer
- Go through the steps and accept the defaults.
Install the PyQt 4.4 bundle (including QT 4.4)
- Go to http://www.riverbankcomputing.co.uk/software/pyqt/download and select the "PyQt-Py2.5-gpl-4.4.2-1.exe" link.
- Save and run the file.
- Go through the steps and accept the defaults.
Run a "Hello World" application
- Go to "Start" -> "All Programs" -> "Python 2.5" -> "IDLE (Python GUI)"
- Open a new window ("File" -> "New window")
- Type the following code inside and save:
import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
button = QPushButton("Hello World", None)
button.show()
app.exec_() - Hit "F5" to run. A window with a single push button should pop up.
For more examples, go to "Start" -> "All Programs" -> "PyQt GPL v4.4.2 for Python v2.5" > "Examples" > "PyQt Examples Source" (For a default installation, this is also located at C:\Python25\PyQt4\examples.) To start, look in the "tutorial" directory.
OLD INSTRUCTIONS
Here are the steps to install and create a simple "Hello World" GUI application using PyQt 4.1.1, Python 2.5, and QT 4.2.2 Open Source edition (GPL) on Windows XP with the MinGW compiler.
Install Python 2.5
- Go to http://www.python.org/download/ and click on "Python 2.5 Windows installer"
- Save and run the Windows installer
- Go through the steps and accept the defaults.
Install MinGW
- Go to http://www.mingw.org/download.shtml
- Download the following "bin" files from the "Current" section:
- gcc-core-3.4.2-20040916-1.tar.gz
- gcc-g++-3.4.2-20040916-1.tar.gz
- mingw-runtime-3.9.tar.gz
- w32api-3.6.tar.gz
- Extract all the files to "c:\mingw"
Install QT 4.2.2 Open Source edition
- Go to the Open Source download page at http://www.trolltech.com/developer/downloads/qt/windows. Note there is also an Evaluation version. This is *not* the one you want.
- Under the "Download" heading, select the "http://ftp.iasi.roedu.net/mirrors/ftp.trolltech.com/qt/source/qt-win-opensource-4.2.2-mingw.exe" link.
- Go through the steps and accept the defaults.
- When you get to the MinGW page, leave the "Download and install minimal MinGW installation" box unchecked and make sure the location of the MinGW installation is set to "c:\mingw". Click "Install".
- You will get an error message which says that the installer could not find a valid "w32api.h" file. You can install the 3.2 version from the mingw site, but the 3.6 version works. Click "Yes" to continue. Click "Finish" to finish the installation.
Install PyQt 4.1.1
- Go to http://www.riverbankcomputing.co.uk/pyqt/download.php and select the "PyQt-gpl-4.1.1-Py2.5-Qt4.2.2.exe" link.
- Save and run the file.
- Go through the steps and accept the defaults.
Check your Environment Variables
- Right-click on "My Computer" and select "Properties"
- Click the "Advanced" tab
- Click "Environment Variables"
- The following variables should be set:
- user variable QTDIR - "c:\qt\4.2.2"
- user variable QMAKESPEC - "win32-g++"
- system variable PATH - include "C:\Qt\4.2.2\bin;C:\Python25\Scripts;C:\Python25;C:\Python25\DLLs;"
Run a "Hello World" application
- Go to "Start" -> "All Programs" -> "Python 2.5" -> "IDLE (Python GUI)"
- Open a new window ("File" -> "New window")
- Type the following code inside and save:
import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
button = QPushButton("Hello World", None)
button.show()
app.exec_()
- Hit "F5" to run.
Technorati tags: python, pyqt