在安装一些Python模块时,大部分是cpython写的模块时会发生如下错误 error: Unable to find vcvarsall.bat。先前的一篇文章:在Windows上安装Scrapy时也讲到了这个问题。当时讲到的方案是,安装VS 2008进行解决,但是Vs 2008又太大,不想装,所以这次想到了另外的方案,同样是上次说的,当时上次很不完整。

方案一:安装Vs2008(实测)

完全的无脑流,安装完问题直接解决。

方案二:安装Vs2010(2016-1-29更新)

上次在电脑上装个Vs2010并不能像 vs2008那样直接解决问题,主要原因是Python 2.7 使用的是 VS 2008编译的,所以Python 2.7默认只能认出VS 2008。

解决办法,在命令行下执行 SET VS90COMNTOOLS=%VS100COMNTOOLS%

  • VS 2010 对应:SET VS90COMNTOOLS=%VS100COMNTOOLS%
  • VS 2012 对应:SET VS90COMNTOOLS=%VS110COMNTOOLS%
  • VS 2013 对应:SET VS90COMNTOOLS=%VS120COMNTOOLS%

或者通过修改Python的源代码进行修改:打开“<python安装目录>\Lib\distutils\msvc9compiler.py”,找到 toolskey = “VS%0.f0COMNTOOLS” % version,直接修改为 toolskey = “VS100COMNTOOLS” 

如果是Python 3,则上面的方法是无效的,原因是Python 3使用的是VS 2010编译的,所以设置应该是这样:

  • VS 2010 无需设置,直接能认出
  • VS 2012 对应:SET VS100COMNTOOLS=%VS110COMNTOOLS%
  • VS 2013 对应:SET VS100COMNTOOLS=%VS120COMNTOOLS%

或修改msvc9compiler.py文件,将: vc_env = query_vcvarsall(VERSION, plat_spec)  中的VERSION设定为已安装的VS版本对应的值:

  • VS2008,则VERSION为9.0
  • VS2010,则VERSION为10.0
  • VS2012,则VERSION为11.0
  • VS2013,则VERSION为12.0
  • VS2014,则VERSION为13.0

注意:Python 3.5升级了distutils,默认使用_msvccompiler.py,在这个文件中可以找到:“ ifversion >= 14 and version > best_version: ”这里的14说明VS版本要在14以上才可以。所以根据这句,我们要安装最新的Visual Studio2015。上面修改msvc9compiler.py的办法没有效果。

另外,微软也提供了解决方案:

Python Version You will need
3.5 and later Visual C++ Build Tools 2015 or Visual Studio 2015
3.3 and 3.4 Windows SDK for Windows 7 and .NET 4.0
(Alternatively, Visual Studio 2010 if you have access to it)
2.6 to 3.2 Microsoft Visual C++ Compiler for Python 2.7

参考链接:https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/

解决方案三:安装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 下载安装即可。

7、再次执行时安装模块时,发现如下错误:

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))

至此,大功告成!

方案四:安装编译好的wheel文件

先安装好wheel: pip install wheel

寻找对应的.whl文件:

http://www.lfd.uci.edu/~gohlke/pythonlibs/

使用 pip install filename.whl  进行安装

参考链接:http://pythonwheels.com/

Python error: Unable to find vcvarsall.bat的更多相关文章

  1. [转]Resolving Python error: Unable to find vcvarsall.bat

    Resolving Python error: Unable to find vcvarsall.bat While installing python package flask-user usin ...

  2. windows上,python安装非官方包,提示error: Unable to find vcvarsall.bat

    在windows机器上安装python非官方包,如果环境只是用于开发,不作任何测试的话,最好的解决办法是: 在Linux上pip安装好之后,把python根目录lib/python3.6/site-p ...

  3. 【转】Windows下Python快速解决error: Unable to find vcvarsall.bat

    转自:http://blog.csdn.net/sad_sugar/article/details/73743863 系统配置:Windows10 x64, Visual Studio 2017, P ...

  4. error: Unable to find vcvarsall.bat

    http://www.crifan.com/python_mmseg_error_unable_to_find_vcvarsall_bat/ [已解决]安装Python模块mmseg出错:error: ...

  5. 在windows下安装lxml 报错error: Unable to find vcvarsall.bat

    刚开始安装 ,我是使用命令pip install lxml直接进行安装,不过出错了 error: Unable to find vcvarsall.bat 解决方案: 1.首先安装wheel,pip ...

  6. 解决 Windows 编译 Fast R-CNN 的 bbox 和 nms 出现的错误 error: Unable to find vcvarsall.bat

    在 Windows 下安装一个底层的 Python 包时(Fast R-CNN 的 bbox 和 nms),遇到 error: Unable to find vcvarsall.bat 错误,看到这个 ...

  7. python27(32位)安装模块报错“error: Unable to find vcvarsall.bat”

    1)首先,下载一个Microsoft Visual C++ Compiler for Python 2.7的补丁,下载地址在这里: http://www.microsoft.com/en-us/dow ...

  8. error: Setup script exited with error: Unable to find vcvarsall.bat

    安装mxnet python版本时遇到“Unable to find vcvarsall.bat”错误搜索一下后查到如下方法: python 3.5.2版本依赖高版本的vs解决办法是安装vs2015的 ...

  9. pip安装scrapy时报错:error: Unable to find vcvarsall.bat

    网上一堆胡说八道的,请看微软官方文章: https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcv ...

随机推荐

  1. 关于ASPXGridview的双击事件弹出 【转】

    在网上找了好长时间,关于ASPXGridview的双击事件弹出ASPxPopupControl,也没有找到适合自己的代码,这里将自己编写出来的代码与大家分享一下 希望我的代码能够对你有所帮助. 直接上 ...

  2. WebStrom 10 注册码(转)

    webStorm : UserName:William ===== LICENSE BEGIN ===== 45550-12042010 00001SzFN0n1bPII7FnAxnt0DDOPJA ...

  3. Codeforces Round #376 (Div. 2)

    A 模拟 #include <cstdio> #include <cstring> int Ans; ]; inline ?x:-x;} inline int Min(int ...

  4. BZOJ 1018 线段树维护图连通性

    用8个bool维护即可分别为LURU,LURD,LDRU,LDRD,LULD,RURD,Side[1],Side[2]即可. Side表示这一块有没有接到右边.Merge一下就可以了.码农题,WA了一 ...

  5. ajax请求!

    ajax请求: var data ='{"useName":"'+name+'",}' $.ajax({ type:"post", url: ...

  6. bookstore网上书店测试缺陷报告2

    Bookstore网上书店系统测试缺陷报告   缺陷编号 01.01.0002 发现人 吴赵昕 记录日期 2016-06-10 所属模块 购物车 确认人 吴赵昕 确认日期 2016-06-10 当前状 ...

  7. 使用注解配置Spring框架自动代理通知

    话不多说上代码 项目架构图及Lib包如下: 第二步创建业务类接口 package cn.happy.day01.entity; /** * 1.业务接口 * @author Happy * */ pu ...

  8. C语言内存分区

    在C/C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局/静态存储区和常量存储区.     栈,就是那些由编译器在需要的时候分配,在不需要的时候自动清楚的变量的存储区.里面的变量通常是局部变 ...

  9. Uncaught TypeError: Cannot read property 'msie' of undefined

    因为图方便,抄了别人写的一个jquerry插件,运行时“var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ...

  10. 【JS】数字转大写中文

    原文参考 逛到一道面试题,数字转大写中文的,搜索学习并记录于此. //自动转换数字金额为大小写中文字符,返回大小写中文字符串,最大处理到999兆 function changeMoneyToChine ...