python Visual C++ 9.0 is required解決方案

error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it … 解決方案

python經過pip或者源碼來安裝某些模塊時,這些模塊包含有c/c++源碼,安裝過程會調用本地的編譯器編譯這些代碼。在Windows平臺下我安裝時候的錯誤消息是「error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it from http://aka.ms/vcpython27」 能夠看出錯誤是因爲沒有找到該vc版本,對應的是vs2008,固然一種解決方法是安裝該版本,但我已經安裝了vs2015,因此我就須要修改下默認的這種配置。python

解決方案

方法一:c++

  • 首先肯定本身安裝vs的版本號,能夠經過查看註冊表,在HKLM\Software\Wow6432Node\Microsoft\VisualStudio\下,如圖 
    這裏寫圖片描述函數

    會有多個數字卡頭的子項,只有安裝的會有對應的InstallDir項,能夠看出我安裝的vs版本是14.0;ui

  • 打開 「python安裝目錄/Lib/distutils/msvc9compiler.py」文件,找到find_vcvarsall函數,在該函數開頭添加 
    version =上面的版本號, 即添加內容爲 「VERSION = 14.0」, 這樣就能夠使用了spa

def find_vcvarsall(version):
    """Find the vcvarsall.bat file

    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.
    """
    version = 14.0            ##添加這行
    vsbase = VS_BASE % version
    ... ...

方法二: 
這種方法更簡單,在環境變量中添加項 VS90COMNTOOLS ,值爲 「VS安裝路徑\Common7\Tools」, 如圖 
這裏寫圖片描述命令行

從新打開命令行程序就能夠使用了。code

相關文章
相關標籤/搜索