Just a couple of days ago I faced the problem that I wanted to write a Python 2.7 module in C. Why in C, you ask? It had nothing to do with number crunching, or performance optimization. It was merely just to create Python bindings for Valve’s Steamworks SDK. This is strictly speaking not a super difficult task in this day and age, except that Python 2.7 uses a fairly old compiler on Windows that is pretty much unavailable nowadays - Microsoft Visual C++ 2008. Fortunately Microsoft seems to have been made aware of this problem. As I found out after a few Google searches, they are now providing an unsupported package containing the required compiler and libraries. Nice! At least that was my thought until I ran into some issues getting it to work with setuptools. Since the package is not supported by Microsoft, I want to share what I had to do to get it to work. Note that I installed the compiler package for all users on my computer, but the steps should be the same for the “current user only” installation - it’s just a different installation directory after all.

So, what were the problems? Well, first of all, the installed compiler does not add any registry values that setuptools’ heuristics for detecting MSVC could find. Not really a big deal because the heuristics fall back to an environment variable - in this case it should be VS90COMNTOOLS. However, as the second issue, the compiler package’s setup routine does not create this environment variable. This should also be a trivial thing to add. Except, thirdly, the compiler package has a different installation path and directory layout from the normal Visual Studio distributions. Thus simply copy/pasting the environment variable for a different visual studio version is not enough, it is needs to be slightly adjusted: Instead of pointing towards [Visual Studio Path]\Common7\Tools\ I had to point it to [Visual Studio Path]\VC\bin. This gets us far enough for setuptools to find the location where it expects the vcvarsall.bat file. All good, right? No! Because, last but not least, the expected vcvarsall.bat file does not exist in this distribution. I had to copy one from my [Visual Studio 2013 Path]\VC\ directory to the VC directory of the Visual C++ compiler for python installation folder, and do a manual edit in this copied batch file: The line with set VisualStudioVersion=12.0 needs to be changed so that the version number is 9.0. And that finally got me going.

Note: there is a vcvarsall.bat file in the root directory of the compiler installation. Copying this into the VC subfolder will not work unless you modify all the paths in there. It’s probably an option as well, but requires more changes than just adjusting a version number.