在安装一些Python模块时,大部分是cpython写的模块时会发生如下错误 error: Unable to find vcvarsall.bat。先前的一篇文章:在Windows上安装Scrapy时也讲到了这个问题。当时讲到的方案是,安装VS 2008进行解决,但是Vs 2008又太大,不想装,所以这次想到了另外的方案,同样是上次说的,当时上次很不完整。
解决方案一:安装Vs2008(实测)
在http://www.skycn.com/soft/appid/10520.html下载Visual C++ 2008 Express Edition(该页面下载的是在线安装版,安装时大约要下载80M的东西)进行安装。
解决方案二:安装Vs2010(未测试)
上次在电脑上装个Vs2010并不能像 vs2008那样直接解决问题,从网上找到如下解决方案,不知是否可行。
打开“<python安装目录>\Lib\distutils\msvc9compiler.py”
找到 toolskey = “VS%0.f0COMNTOOLS” % version,直接修改为 toolskey = ”VS100COMNTOOLS”
解决方案三:安装MinGW(实测)
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文件。找到:
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))
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))
ps:遇到上面的问题是在我安装paramiko时遇到的。针对paramiko模块安装遇到上述问题的解决步骤是:
1、参考上面方案一安装Visual C++ 2008 Express Edition。
2、下载安装PyCrypto的模块。下载地址:https://www.dlitz.net/software/pycrypto/。下载后进入程序目录执行下述命令来安装:
python setup.py build python setup.py install
3、安装paramiko模块。安装时也是进入程序目录执行命令:
python setup.py build python setup.py install
转载请注明:jinglingshu的博客 » Python paramiko模块安装出现error: Unable to find vcvarsall.bat