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

相关文章:

  • 2021-06-23
  • 2022-12-23
  • 2021-07-10
  • 2021-06-25
  • 2021-08-18
  • 2021-12-14
猜你喜欢
  • 2021-10-07
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-01-03
  • 2021-06-07
  • 2022-12-23
相关资源
相似解决方案