Building from Source on Windows 32 bit and 64 bit

T.J. Alumbaugh edited this page Sep 14, 2015 · 12 revisions

This is the start of an unofficial guide to building Python packages on Windows. For now, it is one man's experience, in progress. With input from others, I hope it will grow into a more comprehensive guide.

Optional: Install Windows on a Virtual Machine

By installing Windows on virtual machines, you can work from one computer, switch between 32-bit and 64-bit Windows, and easily roll back to a fresh installation of Windows if needed. This is a good way to operate.

Make disk images from installation DVDs for 32-bit and 64-bit Windows 7.

dd if=/dev/disk1 -of=disk_image.iso

Download VirtualBoxVM, Oracle's software to hosting virtual machines, and start two virtual machines from the two disk images. Activate their licenses, and then save a snapshot of the fresh installation.

Install Visual Studio

We must* use the 2008 release of Visual Studio to compile packages compatible with Python 2.7. We can still obtain the installer officially from Microsoft at When prompted to select optional components, you can uncheck the large Microsoft SQL Server package, which generally should not be necessary for our purposes. The installation process is straightforward.

There are ways to use more modern releases of Visual Studio -- see this and part of this -- but I'm not interested in that here.

Note: if you need to compile Fortran extensions as well, make sure your chosen Fortran compiler supports the "Express" versions of Visual Studio. For example, the Intel Fortran compilers only support the "full" versions of Visual Studio 2008, 2010, or 2012 (depending on the version).

The easiest way to get Python is via Anaconda.

At this stage, on 32-bit Windows, some standard python installations (python install) and conda recipes (conda build ...) work as expected. Packages with pure C or Cython extensions should compile successfully.

Some packages have idiosyncracies, especially those that link to external libraries. The purpose of this wiki page will be to collect advice for handling difficult cases.

Note: For Python 3, use Visual Studio 2010 instead of 2008. (I have not tested this personally.)

Additional Steps for 64-bit Windows

These instructions are gleaned from a README tucked away in the vpython-wx project. I summarize them here in the hope of making them easier to discover and easier to revise.*

Install Windows 7 SDK

Install Windows SDK for Windows 7 and .NET Framework 3.5 SP1 using the installer from You must right-click and "Run As Administrator" or the installation will fail. The full package is a 2.5 GB download. Without the documentation or samples, it's a 422 MB download. Expect a long wait.

Configure Visual Studio 2008 to use Windows 7 SDK

Official Instructions

Follow these instructions to configure Visual Studio 2008 to use the Windows 7 SDK. The gist is:

  • Go to Start > All Programs > Microsoft Windows SDK v7.0 > Visual Studio Registration > Windows SDK Configuration Tool
  • Select Windows 7 SDK (v7.0) the default instead of v6.0.

This will update the Windows 7 SDK build environment and the Visual Studio 2008 IDE build environment to use the Windows 7 SDK headers, libraries and tools. You can also use this tool to switch it back again.

Revisions to Official Instructions

Apparently, the official instructions for Visual Studio 2008 are not fully compatible with Visual Studio 2008 Express. A blog post explains the problems and how to fix them. At the end, a script is provided to execute to the procedure and, according to the vpython README linked above, it works.

An Important Fix

Open Visual C++ 2008 (Express Edition). Under Tools > Options > Projects and Solutions > VC++ Directories you can see what resources are invoked for Platform x64. You should see $(VCInstallDir)bin, where $(VCInstallDir) represents C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC.

In this VC folder there is a major error in the file vcvarsall.bat. These lines

if not exist "%~dp0bin\x86_amd64\vcvarsx86_amd64.bat" goto missing
call "%~dp0bin\x86_amd64\vcvarsx86_amd64.bat"

must changed to

if not exist "%~dp0bin\vcvarsx86_amd64.bat" goto missing
call "%~dp0bin\vcvarsx86_amd64.bat"