skip to content | skip to sidebar

building Python extensions using VC++ 2005 Express

May 1st, 2007

Here’s a quick roundup on how to build Python extensions using the Microsoft Visual C++ 2005 Express Edition compiler. This is meant for people who need to build Python extension from source using the accompanying setup.py script.

There’s no rocket science or magic involved. Just five easy click-through steps. Well, the last one actually is a bit of manual editing, but not so much. And the best thing of all: it’s all available for free!

  1. Probably you will already have Python installed, but for the sake of completeness: download and install Python (get one of the Windows Installers)
  2. Download and install VC++ 2005 Express (pretty obvious)
  3. At the end of the VC++ 2005 Express installation, you will be asked to register your copy. Please, do so. It’s for free, and if you don’t do it, your copy will stop working after a week or so. If you’ve skipped registration, you can still do it from the Help menu by clicking on Register Product.
  4. VC++ 2005 Express is a limited edition and is not capable of building Win32 applications out of the box (it can build .NET applications though). For the most simple extensions you probably won’t need that, but sooner or later you will hit that limitation. Fortunately, you can solve that issue (for free again) by installing the Windows Platform SDK. If you follow the previous link, you will notice it actually goes a download page for the Windows Server 2003 R2 Platform SDK. That’s OK, it’s exactly what you need. Caution: if you go looking for the Windows Platform SDK via google, you probably will find a previous version. So just use that link I gave you.
  5. By now, you have installed on your computer everything you need to build Python extensions using Visual C++ 2005 Express Edition. All that’s is left to do is to update some settings in VC++ 2005 Express so it can find the necessary headers and libraries. Open up the Options dialog from the Tools menu. On the left, select VC++ Directories from the node Projects and Solutions. In the top-right corner, you’ll then find a dropdown box titled Show directories for. Add the following directories:
    • Executable files:
      • C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin
      • C:\Python25
    • Include files:
      • C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include
      • C:\Python25\include
    • Library files:
      • C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib
      • C:\Python25\libs

That’s it! Enter setup.py install and go!

2 Responses to “building Python extensions using VC++ 2005 Express”

  1. halida Says:

    could you provide a pre-compiled package for us? thanks.

  2. Bramz Says:

    Hi Halida,

    I’m not sure what you mean. What would you like to see packaged?

    Kind regards,
    Bram.