解决Unable to find vcvarsall.bat的办法

基本环境:
1.python34
2.win32系统
3.VisualStudio 2008

使用easy_install安装numpy时,提示:
“error: Setup script exited with error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat).”
根据网上的资料查看C:\Python34\Lib\distutils\msvc9compiler.py的内容
该文件通过检索注册表来找到vcvarsall.bat的安装目录,该文件检索的注册表路径为
‘Software\Microsoft\VisualStudio\10.0\SETUP\VC’,获取其下的注册表项:ProductDir对应的值

本机环境已安装了vs 2008,对应的注册表路径为’Software\Microsoft\VisualStudio\9.0\SETUP\VC’

通过修改C:\Python34\Lib\distutils\msvc9compiler.py中第187行:

return majorVersion + minorVersion

改为

return 9.0

这次出现新的错误:
File “C:\Python34\lib\distutils\msvc9compiler.py”, line 287, in query_vcvarsall
raise ValueError(str(list(result.keys())))
ValueError: [‘path’]

查看query_vcvarsall函数,这个函数是在查找系统环境变量

interesting = set(("include", "lib", "libpath", "path"))

环境变量得包含这四种,少了都会报错
继续研究代码,发现py在找这几个文件(352行)

self.cc = "cl.exe"
self.linker = "link.exe"
self.lib = "lib.exe"
self.rc = "rc.exe"
self.mc = "mc.exe"

找到这几个文件的路径,并新建环境变量
lib=C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\
libpath=C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\
include=C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\

继续出现新的错误:
File “numpy\core\setup.py”, line 686, in get_mathlib_info
RuntimeError: Broken toolchain: cannot link a simple C program

最后请下载numpy-1.9.2-win32-superpack-python3.4.exe进行安装,这次很顺利,一次成功

你可能感兴趣的:(解决Unable to find vcvarsall.bat的办法)