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

转载于:https://www.cnblogs.com/xueliangliu/archive/2012/04/06/2962165.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值