Thursday, December 26, 2013

nmake: Installing PyQt In Windows 7 with Visual Studio .NET 2010

For those of you interested in pursuing Python development involving a front-end GUI made from Qt, and don't know how to get started on Windows 7, this is what you need to do.  This could generalize to any software you might wish to install with the "nmake" tool, which allows you to "configure", "make", and "make install" different software packages in much the same way you would on a Linux box.

My setup:

  • Windows 7 machine
  • Windows 7.0 APIs installed (C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A)
  • Microsoft Visual C++ 2010 Ultimate (will hopefully work with Express too)
First, for our specific purpose, download and install Qt if you haven't done that already.  It'll take so long that you ought to have plenty of time to run the next step (building SIP) in parallel and still have time to play at least a couple rounds of solitaire.

In general, before you build from any Makefile in Windows, download and unzip your sources into a known location.  If you plan to be building from source frequently, you may wish to simply add these as environment variables in your "System" settings before you open up a Command Prompt.  Otherwise, just add them after you start your Command Prompt session.  Here's what you need to do:
  • set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include
  • set LIB=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib
  • Add to your PATH:
    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin
    for MT.exe file location
If you chose the latter approach, you can just run those first two bullets as-is in the Command Prompt.  Then, the third one would be:

set PATH=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin;%PATH%

This is it.  Then, cd into the directory where you downloaded your source to, and run the usual three commands, with the noted twists:
  • python configure.py
    Note this one takes some options that pertain to your development environment.  It didn't pick it up correctly for me, so I had to specify it manually with the flag -p win32-msvc2010. You can see all options by using the flag --show-platforms.
  • nmake
  • nmake install
The second step among these three is where you'd run into potential problems.  Usually they''re correctable by ensuring the paths are indeed correct.  The others should go smoothly.

For PyQt in particular, you need to install SIP first, and then PyQt (using the means described above).  Both of these can be found on the Riverbank Computing website.  To get the PyQt installation to work (and avoid the errors about not having a working Qmake present), make sure you have Qt installed, and then add this to your PATH:

C:\Qt\5.2.0\msvc2010\bin

Or whatever your equivalent path is, assuming you plan to use the MS VC 2010 toolchain as I've described before.  Several other toolchains are supported here, and this will help the system find qmake properly and proceed with installation.

As for using PyQt with Qt Designer to build a user interface, I might save that for a later date.  I hope you had a Merry Christmas (or maybe s/Christmas/$yourFavoriteHoliday/g), and have a Happy New Year since this will probably be my last post of 2013.  See you next year! 

1 comment:

  1. Just to reiterate, make sure C:\Qt\5.2.0\msvc2010\bin is permanently in your PATH. Otherwise, you'll have problems running Python Qt apps in the future.

    ReplyDelete