solution for "cannot find vcvarsall.bat" in Python

When building some package with python in windows, the command is

python setup.py build

However, if you use Visual Studio as the compiler, sometime there is an error shown as :

error: Unable to find vcvarsall.bat

But VS has been installed in this computer, has not it?

The error is from a logical error in the distutils of python.
In the file of msvc9compiler.py, there is a function called: get_build_version. In this function is used to get the version of VS that is used to build your python, and the value are used as the VS version in your computer. It does not make sense at all!

A solution is to find the version of VS in your computer from register. The code as followed:


def get_build_version():
"""Return the version of MSVC in your computer.
"""
p = r"Software\Wow6432Node\Microsoft\VisualStudio"
for base in HKEYS:
try:
h = RegOpenKeyEx(base, p)
except RegError:
continue
key = RegEnumKey(h, 0)
if key:
return float(key)
return None

posted on 2012-04-06 17:58  xueliangliu  阅读(261)  评论(0编辑  收藏  举报

导航