首先說明這個方法並不是萬能的,也查了些資料,說安裝了vs這個是可以通過的,但我的電腦上貌似行不通,不管是微軟的vs,還是玩魔獸的vs客戶端都有還是行不通,也有可能是我裝的是vs2010、vs2012版本太高了,所需要的文件沒有了, 據說是要vs2008,這個我就沒有去嘗試啦,有興趣的朋友可以去試下,記得把結果告訴我哈。
現在我們用另一種無需安裝龐大的vs的方法
1、下載安裝MinGW,下載地址為:http://sourceforge.net/projects/mingw/files/latest/download?source=files
2、在MinGW的安裝目錄下找到bin文件夾,找到mingw32-make.exe,復制一份更名為make.exe
3、把MinGW的路徑添加到環境變量path中,比如我把MinGW安裝到D:\MinGW\中,就把D:\MinGW\bin添加到path中;
4、在<python安裝目錄>\distutils增加文件distutils.cfg,在文件里輸入
[build]
compiler=mingw32
保存;
5、執行原先的模塊安裝,發現還是報錯,報錯內容為:error: command ’gcc’ failed: No such file or directory 解決方案是將D:\MinGW\lib再添加到PATH中。
6、如果安裝過程中出現 error: Could not find ‘openssl.exe’ 則直接到http://pypi.python.org/pypi/pyOpenSSL/0.13 下載安裝即可。
6、再次執行時安裝模塊時,發現如下錯誤:
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文件。找到:
1
2
3
4
5
6
7
|
self.set_executables(compiler=
'gcc -mno-cygwin -O -Wall'
,
compiler_so=
'gcc -mno-cygwin -mdll -O -Wall'
,
compiler_cxx=
'g++ -mno-cygwin -O -Wall'
,
linker_exe=
'gcc'
,
linker_so=
'%s -mno-cygwin %s %s'
% (self.linker_dll, shared_option,
entry_point))
|
修改為:
1
2
3
4
5
6
7
|
self.set_executables(compiler=
'gcc -O -Wall'
,
compiler_so=
'gcc -mdll -O -Wall'
,
compiler_cxx=
'g++ -mno-cygwin -O -Wall'
,
linker_exe=
'gcc'
,
linker_so=
'%s -mno-cygwin %s %s'
% (self.linker_dll, shared_option,
entry_point))
|
至此,大功告成!