Python 安裝模塊error之 Unable to find vcvarsall.bat

在安裝一些Python模塊時,大部分是cpython寫的模塊時會發生以下錯誤 error: Unable to find vcvarsall.bat。先前的一篇文章:在Windows上安裝Scrapy時也講到了這個問題。當時講到的方案是,安裝VS 2008進行解決,可是Vs 2008又太大,不想裝,因此此次想到了另外的方案,一樣是上次說的,當時上次很不完整。html

解決方案一:安裝Vs2008(實測)python

徹底的無腦流,安裝完問題直接解決。windows

解決方案二:安裝Vs2010(未測試)scrapy

上次在電腦上裝個Vs2010並不能像 vs2008那樣直接解決問題,從網上找到以下解決方案,不知是否可行。測試

打開「<python安裝目錄>\Lib\distutils\msvc9compiler.py」ui

找到 toolskey = 「VS%0.f0COMNTOOLS」 % version,直接修改成 toolskey = 「VS100COMNTOOLS」 spa

解決方案三:安裝MinGW(實測).net

一、下載安裝MinGW,下載地址爲:http://sourceforge.net/projects/mingw/files/latest/download?source=filescode

二、在MinGW的安裝目錄下找到bin文件夾,找到mingw32-make.exe,複製一份改名爲make.exeorm

三、把MinGW的路徑添加到環境變量path中,好比我把MinGW安裝到D:\MinGW\中,就把D:\MinGW\bin添加到path中;

四、在<python安裝目錄>\distutils增長文件distutils.cfg,在文件裏輸入

[build]
compiler=mingw32

保存;

五、執行原先的模塊安裝,發現仍是報錯,報錯內容爲:error: command ‘gcc’ failed: No such file or directory  解決方案是將D:\MinGW\lib再添加到PATH中。

六、若是安裝過程當中出現 error: Could not find ‘openssl.exe’ 則直接到http://pypi.python.org/pypi/pyOpenSSL/0.13 下載安裝便可。

六、再次執行時安裝模塊時,發現以下錯誤:

D:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall 「-ID:\Program Files\Python27\inc
lude」 「-ID:\Program Files\Python27\include」 「-ID:\Program Files\Python27\PC」 -c
../libdasm.c -o build\temp.win32-2.7\Release\..\libdasm.o
cc1.exe: error:unrecognized command line option ‘-mno-cygwin’
error: command ‘gcc’ failed with exit status 1

緣由是gcc 4.6.x 之後再也不接受-mno-cygwin爲了解決這個問題須要修改<python安裝目錄>\distutils\cygwinccompiler.py文件。找到:

 self.set_executables(compiler=&#039;gcc -mno-cygwin -O -Wall&#039;,
                             compiler_so=&#039;gcc -mno-cygwin -mdll -O -Wall&#039;,
                             compiler_cxx=&#039;g++ -mno-cygwin -O -Wall&#039;,
                             linker_exe=&#039;gcc&#039;,
                             linker_so=&#039;%s -mno-cygwin %s %s&#039;
                                        % (self.linker_dll, shared_option,
                                           entry_point))

修改成:

self.set_executables(compiler=&#039;gcc -O -Wall&#039;,
                             compiler_so=&#039;gcc -mdll -O -Wall&#039;,
                             compiler_cxx=&#039;g++ -mno-cygwin -O -Wall&#039;,
                             linker_exe=&#039;gcc&#039;,
                             linker_so=&#039;%s -mno-cygwin %s %s&#039;
                                        % (self.linker_dll, shared_option,
                                           entry_point))

至此,大功告成!

相關文章
相關標籤/搜索