in Code, Geeklife, Qt4

How to build PyQt4 for Windows

– Make sure you don’t have cygwin or C:devkitPromsysbin in your path,
or else your make files can end up trying to run the Makefile using ‘sh’ and all
the makefile we’re about to use are meant to run from the windows command line.

If for some odd reason you type ‘sh’ on your windows command line and you see something like:

sh-2.04$

You’re likely to find this later on:

/bin/sh: -c: line 2: syntax error: unexpected end of file

– Install Qt open source, with the exe installer, this will attempt to install
ming if you don’t have it installed, say yes, mingw rocks.

– Make sure you have the following Windows environment variables set:

QTDIR = c:Qt4.2.2
QTMAKESPEC = win32-g++

– Make sure you have Python2.5, Qt bin and Mingw bin folders on your path

PATH = %PATH%;c:Mingwbin;c:Mingwlibexecgccmingw323.4.2;c:python25bin;c:Qt4.2.2bin

– Get pexports just in case the Qt doesn’t have libQtCore4.a on its lib/
folder.

You can download pexports at:
http://www.emmestech.com/software/cygwin/pexports-043/download_pexports.html

If you don’t have that libQtCore4.a you won’t be able to build PyQt.

So you’ll need to do this, go to your Qt bin folder, say:
c:Qt4.2.2bin

And run this:

pexports QtCore4.dll > Qt4Core4.def
dlltool -dllname QtCore4.dll –def QtCore4.def –output-lib libQtCore4.a

Move the resulting file, libQtCore4.a, to c:Qt4.2.2lib

COMPILING SIP:
– PyQt needs “sip” to be able to bind the Qt libraries, sip will generate the necessary C++ code.
To install sip, get its source code, extract it to a folder say:

c:sip-4.5.2

Once inside run it’s configure.py like this:

python configure.py -p win32-g++

That will create the Makefiles, then you will make it using

mingw32-make

and

mingw32-make install

Now, I’m not sure what’s the environment variable of Mingw library path,
and I was having errors from the compilation of PyQt, telling me it couldn’t
find the sip libraries, so this is what I did:

– Copy all the .o files from c:sip-4.5.2siplib to c:mingwlib
– Copy all the .h files from c:sip-4.5.2siplib to c:mingwincludes

– Now it’s finally time to compile PyQt.
Uncompress the PyQt zip with the source (not the binary, if not we wouldn’t be doing this),
do it at the root of your hardrive (C:), you’ll end up with a folder named similar to this:

c:PyQt-win-gpl-4.1.1

Go in there and do this:
python configure.py
mingw32-make (this will take a long time, it will wrap every Qt C++ library on a new .cpp file which will be then compiled to exist as a python binding)
mingw32-make install

If you have any errors write me a comment on this post

Leave a Reply for Roger Ho Cancel Reply

Write a Comment

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Big thanks for this article=)
    but I one error =
    ——–
    Error: Failed to determine the layout of your Qt installation. Try again using
    the –verbose flag to see more detail about the problem.
    ——-

Webmentions

  • Make /bin/sh 1 Syntax Error Unexpected March 9, 2013

    […] How to build PyQt4 for Windows | Gubatron.com – Feb 23, 2007. sh-2.04$. You're likely to find this later on: /bin/sh: -c: line 2: syntax error: unexpected end of file. – Install Qt open source, with the exe installer, this will attempt to install ming if you don't have it installed, say yes, mingw rocks. – Make sure you have the following Windows environment variables set:. […]