Python 2.7 was released on Jul. 3rd, and for many developers and end users that means recompiling a bunch of libraries. I made this quick and dirty guide to show you how to use Visual Studio 2010 Express to compile your libraries without having to build another mingw32 toolchain or search for an old version of Visual Studio.
Before you start, have a look at Christoph Gohlke’s Python Extension Packages for Windows. You may find a binary package there and not need to compile it at all.
If you didn’t find what you need, don’t stress. Just grab Visual Studio 2010 Express if you don’t already have it and follow along.
First, msvc9compiler is a mess. If you try to run setup.py build, you’ll be greeted with an error:
error: Unable to find vcvarsall.bat
Instead of messing around with huge edits that you find on mailing lists or Stack Overflow, just open up
and replace line 243 with this:
toolskey = "VS100COMNTOOLS"
since you have it open, you can avoid manifest errors caused by unruly setup.py scripts by adding
after line 647. This is optional, and not a very elegant solution…
Now you need to set an environmental variable in Windows so that Python can find Visual Studio.
Name = VS100COMNTOOLS Value = C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\
Typically, you just need to add it via the “Advanced System Settings” link in Control Panel\System and Security\System.
Alternatively, you can set it globally in a command prompt with this command:
set VS100COMNTOOLS="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\"
or per user with setx instead.
If you happen to use virtualenv, you can add it to your env\Scripts\activate.bat script.
A final note: If you intend to redistribute you packages, you should be aware that the end user will likely need msvcr100.dll (C:\Windows\SysWOW64 on Windows 7 x64) to load any compiled libraries you have included. Pointing them to the appropriate Microsoft Visual C++ 2010 Redistributable Package should suffice: