1. 程式人生 > >Python: Windows下pip安裝庫出錯:Microsoft Visual C++ 9.0 is required < Unable to find vcvarsall.bat

Python: Windows下pip安裝庫出錯:Microsoft Visual C++ 9.0 is required < Unable to find vcvarsall.bat

一直在用Linux, 最近想在windows下使用python。 

當我想安裝Matplotlib module的時候, 出現以下錯誤。Microsoft Visual C++ 9.0 is required < Unable to find vcvarsall.bat>  

想起來自己一直沒有安裝VS  - -!。 後來安裝之後錯誤依舊。

後續解決辦法如下:

For Windows installations:

While running setup.py for package installations, Python 2.7 searches for an installed Visual Studio 2008. You can trick Python to use a newer Visual Studio by setting the correct path in VS90COMNTOOLS

environment variable before calling setup.py.

Execute the following command based on the version of Visual Studio installed:

  • Visual Studio 2010 (VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS%
  • Visual Studio 2012 (VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS%
  • Visual Studio 2013 (VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS%

python27在執行setup.py安裝時, 會預設尋找visual studio 2008來編譯其中的C++檔案。 但我安裝的是VS2013, 所以需要執行
SET VS90COMNTOOLS=%VS120COMNTOOLS% 改變配置。 

然後錯誤消失了。

但出現了新的錯誤。 如下:

valueerror(str(list(result.keys()))) valueerror u'path'

I bet you're not using VS 2008 for this :)

There's def find_vcvarsall(version): function (guess what, it looks for vcvarsall.bat) in distutils with the following comment

At first it tries to find the productdir of VS 2008 in the registry. If that fails it falls back to the VS90COMNTOOLS env var.

If you're not using VS 2008 then you have neither the registry key nor suitable environment variable and that's why distutils can't find vcvarsall.bat file. It does not check if the bat file is reachable through the PATH environment variable.

The solution is to define VS90COMNTOOLS variable to point to Tools directory of Visual Studio.

Typically, extension modules need to be compiled with the same compiler that was used to compile Python.

Martin v. Loewis in the email titled Download Visual Studio Express 2008 now on python-list mailing list states the same

Python 2.6, 2.7, and 3.1 are all built with that release (i.e. 2008). Because of another long tradition, Python extension modules must be built with the same compiler version (more specifically, CRT version) as Python itself. So to build extension modules for any of these releases, you need to have a copy of VS 2008 or VS 2008 Express.

簡言之:看到最終的解決辦法如下: 

必須安裝VS2008.。。。。。。。。。。。。

追加(如果你不想安裝vs2008): 

最終解決辦法:

over.....