How to Compile PyQt4 for Python 2.6 AMD64 (64 bit) on Windows x64

PyQt 4.5.4 for Python 2.5 amd64
PyQt 4.5.4 for Python 2.6 amd64

Recently I've written an interface for the first time with PyQt4 in Linux for one of our pipeline related scripts. It was working very well under Linux, until I decided to check how it is going to look under Windows x64.

Well, it didn't take too long for me to recognize that there is no PyQt4 for Python 2.5 amd64. So I decided to compile my own. By the way you will see that I started for Python 2.5 but compiled for Python 2.6, it is just because, in a panic mode I've installed Maya 2010 to see if the package I found for PyQt4 for Python 2.6 amd64 for Windows x64 will work under. But no it wasn't ( actually it was, but I didn't know that I should add the path that contains the Qt DLLs to environment path ). So I dived in to compiling PyQt4 for Python2.6 amd64 for Windows x64.

Here you can find the How-To of that compilation...

You need these packages and programs:

MS Visual Studio 2008
Python 2.6 amd64
Qt 4.5.2 SDK for Windows
Sip 4.8.2 Source
PyQt4 4.5.4 Source
Nullsoft scriptable install system

Lets start:

  1. Install Python 2.6.2 amd64:
    • install it to C:\Python2.6
    • if you have already installed it somewhere else, in the rest of this "how-to" use that path instead of C:\Python26

  2. compile sip:
    • download sip-4.8.2.zip
    • unzip sip-4.8.2.zip to C:\sip-4.8.2
    • open up the Visual Studio 2008 x64 Win64 Command Prompt from start menu/programs/etc.
    • run the commands below
    • cd C:\sip-4.8.2
    • C:\Python26\python configure.py -p win32-msvc2008
    • nmake
    • nmake install
    • open the python interpreter and check the module by using:

      from sip import *
      print SIP_VERSION_STR


      if it doesn't give any error messages about a DLL or something, it is installed correctly

  3. compile Qt4:
    • download Qt SDK for Windows
    • install it to C:\Qt\4.5.2 not to 2009.03
    • delete the two tmp files: (they were causing problems in the middle of the compile process, very annoying to start again)
      C:\Qt\4.5.2\qt\src\3rdparty\webkit\WebCore\tmp\moc\{debug,release}_shared/mocinclude.tmp)
    • open up the Visual Studio 2008 x64 Win64 Command Prompt
    • run the commands below
    • cd C:\Qt\4.5.2\qt
    • set QTDIR=C:\Qt\4.5.2\qt
    • set PATH=%PATH%;C:\Qt\4.5.2\bin
    • configure -opensource -platform win32-msvc2008
    • enter "y" for the question
    • nmake ( and go to have a lunch or dinner, seriously, it took 3 hours in my computer, it will be around on yours too )
    • nmake install
    • congratulations you have built Qt4 x64 for Windows x64
      (NOTE 1: you can create a batch file that runs the 'configure' then the 'nmake' and then the 'nmake install' commands, but when you run this batch file wait for 1 seconds to the question in configure step then leave :) )
      (NOTE 2: because we didn't specified a -prefix option in configure, it will compile it over the source directories )

  4. compile PyQt4:
    • download PyQt4 4.5.4 Source
    • unzip the PyQt4 source to C:\PyQt-win-gpl-4.5.4
    • open Visual Studio 2008 x64 Win64 Command Prompt
    • run the commands below
    • set QTDIR=C:\Qt\4.5.2\qt
    • set Path=%PATH%;C:\Qt\4.5.2\qt\bin\
    • cd C:\PyQt-win-gpl-4.5.4
    • C:\Python26\python configure.py -w
    • enter "yes" to the question
    • nmake ( again it takes some time )
    • nmake install
    • now you should be able to use PyQt4, but if there is an error message saying:

      Python 2.6.2 (r262:71605, Apr 14 2009, 22:5+:60) [MSC v.1500 64 bit (AMD64)] on win32
      Type "help", "copyright", "credits" or license" for more information.
      >>> from PyQt4 import QtCore
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      ImportError: DLL load failed: The specified module could not be found
      >>>


      you need to add the folder that contains Qt DLLs to the environment path variables, by using the Control Panel -> System -> Advanced -> Environment Variables

  5. Nullsoft installer to make installable binary package:
    • download and install Nullsoft installers latest version
    • right click C:\PyQt-win-gpl-4.5.4\PyQt.nsi and select "Compile NSIS Script"
      ( unfortunatelly the script gives a lot of errors, you need to copy/paste some files and create folders by your self according to the complains of the compiler )


for Python 2.5, compiling PyQt4 for Python 2.5 x64 is quite similar, you just need to use vs2005 and its x64 command prompt compiler with the nearly the same commands, just replace win32-msvc2008's with win32-msvc2005, that's all...

EDIT 1:

for Python 2.6 version of PyQt4 you need to install Microsoft Visual C++ 2008 SP1 Redistributable Package (x64) also

for Python 2.5 version of PyQt4 Microsoft Visual C++ 2005 SP1 Redistributable Package (x64) also

EDIT 2:

I've compiled the Python 2.5 amd64 version of PyQt4 for Windows x64... Download (the Phonon Multimedia Framework is only supported by python 2.6 an later)

Comments

Threader Slash said…
Hey Man... Thanks a lot!
Cheers - ThreaderSlash
Guy said…
thanks for this tut.
very useful , i was looking for the 64 bits version of pyQt for python 2.6.

by the way I used the visual express 2008 64 bits version (64bits compiler from windows SDK).
Worked great.

I am also a TD in a 3d STUDIO....
Cheers
Wasim Khan said…
Hey, Very much thanks for the 64 bit version of Pyqt. I've installed it on Windows7 and it works perfectly.

Im just getting into Qt (With Maya)
Adam said…
I having some troubles. nmake install didn't seem to copy any qt files. Apparently they were already there and it didn't write over them. Had lots of "File cannot be written over itself" output. What am I doing wrong?
yeah I now, just ignore them, it is because you (we) are installing it to the directory where it is compiled...
Unknown said…
when I tried this command:

C:\Python26\python configure.py -p win32-msvc2008

it wouldn't work because there is no configure.py file in the python26 folder. How do I get it?
the configure.py is in sip folder not in python26 folder so just try to change your directory to sip root folder before running configure.py

for example:
cd C:\sip-4.8.2
Unknown said…
ah ok, I needed to change directory one more time to reach the configure.py file. Thank you for the quick response!
Unknown said…
do you have the pyqt 4.5.4 source file? I have been looking online and can't seem to find the source file, just the binary for that version
Adam said…
Was having trouble. Running "from PyQt4 import QtCore" gave me "%1 is not a valid Win32 application." Discovered that the newly compiled 64-bit versions of the DLL's were put into C:\Qt\4.6.0\qt\bin not C:\Qt\4.6.0\bin as in the standard installation. Changing the path to the "qt" version resolved my import errors. A bit of clarification on paths might be helpful for readers new to compiling like myself. :) Thanks for the post.
valefar said…
Hello Ozgur,

To compile for python 2.5.2, do I use the following sources?

Python 2.5.2 amd64
PyQt 4.5.4-1 Source
Sip 4.8.2 Source
Qt 4.5.2 SDK for Windows

Also, where can you download these older sources and determine which one you need? I noticed both Riverbank and Nokia don't have a link to older builds. Or did I miss the link. :O.

Python 2.5.2 amd64
PyQt 4.5.4-1 Source
Sip 4.8.2 Source
Qt 4.5.2 SDK for Windows


Thanks for providing your experience with how to compile.

Thanks,

V
As I remember I've both compiled for Python 2.5 and 2.6 with the same versions of Qt, Sip and PyQt... The only difference should be QScintilla, it shouldn't compile for Python 2.5, but it shouldn't be a problem...
Unknown said…
Hello Ozgur,

I tried to build against the lastest versions and get errors.
I heard there could be a conflict with not building with MinGW. The newest version of QT 4.6.0 provides an option to install MinGW and I'm wondering if that's why I'm getting errors.

Thanks,

F
Unknown said…
Hello Ozgur,

I provided a link below to the errors I recieved. Thanks for taking a look!

V


Link to errors
I think you skipped one step:

delete the two tmp files: (they were causing problems in the middle of the compile process, very annoying to start again)
C:\Qt\4.5.2\qt\src\3rdparty\webkit\WebCore\tmp\moc\{debug,release}_shared/mocinclude.tmp)
Unknown said…
Oh I see. I think I did delete that but the tmp files are still there.
I will run it again. Do you have to run the configure step again, or should I reinstall Qt and start from scratch?


Thanks,

V
Unknown said…
Hello Ozgur,

I deleted the mocinclude.tmp file in both directories and got the exact same error.
I noticed during the nmake process, it spawend new mocinclude.tmp files in the same directories.
I did however find another location with the mocinclude.tmp file. Do think the compiler is sourcing from this directory as well?
C:\Qt\4.6.0\qt\src\script\tmp\moc\debug_shared

Thanks again for help!
Adam said…
In the latest qt version, there are two sets of those tmp files that need deleting. Not sure the path to the second set off the top of my head, but if you search the qt folder for those tmp file names you should find them.
Unknown said…
Hello,

I successfully compiled QT 4.6.0 against python 2.5.2.
When I ran the nmake install, I kept seeing "Cannot perform a cyclic copy" and Can overwrite over itself messages. Not sure if this is common or not.

Link error 2
congrats :)
just ignore the errors...
Unknown said…
Thanks Ozgur! I think I'm almost there! :)
I tried to build PyQt and got some new errors.

Have you seen this error before?
PyQt errors
No, I haven't...

are you running the nmake from the standart command prompt or are you using the Visual Studio 2008 x64 Win64 Command Prompt ?
Unknown said…
I'm running it from the Visual Studio 2008 x64 Win64 Command Prompt.
Unknown said…
Correction! I'm running it from Visual Studio 2005 x64 Win64 Command Prompt.
allright, because python 2.6 is compiled with MSVC 2008, to have binary compatibility you need to use 2008 for python 2.6 and 2005 for python 2.5... may be this is the cause of your problems
Unknown said…
The errors I received are from msvc 2005.
I'm at a loss with what it could be.
Below are all the sources I used.



Microsoft Visual 2005 x64 Command Prompt
Python 2.5.2 64 bit

PyQt-win-gpl-4.6.2 compiled with errors
sip-4.9.3 - compiled ok
Qt 4.6.0 - compiled ok
http://www-01.ibm.com/support/docview.wss?uid=swg21325326

apparently you need to re-install your MSVC 2005
Unknown said…
Ah ha! This is interesting!
I will give that a try!

Thanks for your help!

V
Unknown said…
Hello,

Ok... I finally got it all compiled!

When I run the NSIS on PyQt.nsi
it stops with this error:
File: "C:\Python25\Lib\site-packages\PyQt4\sip.exe" -> no files found.

The sip.exe file is located in C:\sip-4.9.3\sipgen. Was this supposed to be installed in \Python25\Lib\site-packages\PyQt4\ or should I manually copy it?

Thanks,

V
yeah you can manually copy them, let me warn you that the nsi script will give you alot of errors, try to edit the script with a text editor that shows line numbers. So you can just delete the lines that give errors (mostly about phonon)
Unknown said…
Ok.. sounds good! Yeah, I noticed there was a lot of errors. I also got some incorrect paths for the qt dll's.

Thanks again!

V
Unknown said…
Looks like I do have a lot of path problems. What config files are used for the proper paths for everything(SIP, Qt, and PyQt)?
Does the PyQt.nsi remap all the paths when I create a binary installer package?

Thanks,

V
Doug's Blog said…
This comment has been removed by the author.
Doug's Blog said…
Hello Ozgur, thanks for the tutorial.
I got a quick question, when trying to do the c:\Python26\python configure.py -w (for the PyQt), i get the following error:
"C:\Python26\sip" -k -o -x VendorID -t WS_WIN -x PyQt_OpenSSL -x PyQt_NoPrintRangeBug -t Qt_4_4_1 -x Py_v3 -g -a QAxContainer.api -c QAxContainer -b QAxContainer\QAxContainer.sbf -I c:\PyQt-win-commercial-4.7\sip c:\PyQt-win-commercial-4.7/sip/QAxContainer/QAxContainermod.sip
sip: QVariantMap is undefined
Error: Unable to create the C++ code.

Help please :)
Unknown said…
I am also attempting to build PyQt for 64bit. I am using Visual Studio 2008 Express however so I downloaded Windows SDK for Windows Server 2008 and .NET Framework 3.5 - Version 6.1

This gives me a CMD Shell that says its x64 however when I attempt to nmake sip I get errors.

First I run the configure.py which works, next I run nmake which fails:

LNK1112: module machine type 'x64' conflicts with target machine type 'X86'

Any ideas?
Anonymous said…
Hello Ozgur, thanks for this blog post. I am trying to compile sip for python 2.5. The compile works fine, but I'm still getting DLL errors when im trying to import in python 2.5. I know I am using 64 bit python, and have tried both vs2005 and vs2008 64-but compilers, only to get the same DLL error when importing SIP. Any clue?
sorry guys, especially ryant and john, I missed your comments.

Ryant, it should be about a missing flag, I don't remember the exact flag, but there was a flag telling the compiler about the target architecture, it should be that, on the other hand the cmd prompt from the express edition should already set these kind of things via environment variables, so I don't have a clear idea about your problem. Try googling the "LNK1112" error...

John, I mentioned that in my post, it is because your system couldn't find the Qt dll's, which are placed in the original qt directory ( C:\Qt\4.x.x\qt\bin\etc. just don't remember exactly). You should add the path that contains those dlls to the system path, or you should copy them to somewhere python searches already, like the c:\pythonx.x\lib\site-packages\PyQt4 folder

I hope it is not too late to answer your questions, and hope it will be helpful.

Next week, if I'm going to have time, I'll give it a try to compile the latest PyQt4 build for the latest Qt.
and sorry Doug, I've no idea about the problems occurring while compiling the newest versions of Qt, next week maybe...