在安装一些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. Enable rsh on MAC OS with command line

    1. Enable rsh on macos. 1). os version (10.0) Enabling the "Allow remote login" option tur ...

  2. wireshark流跟踪和分析

  3. WPF与WinForm开发有什么区别?

    转自http://hi.baidu.com/leoliu83/blog/item/1d1a4a66dcb41134aa184cfd.html WPF开发于WinForm之后,从技术发展的角度,WPF比 ...

  4. Photoshop制作的海报修改~

    经过几天的征求意见,感觉还是要重新制作,于是把颜色删减了不少 . 这次运用了蒙版和渐变,但感觉效果不太好.再改.. 后来觉得给人的单身感有点少.. 不知道感觉如何,但自己觉得比以前好看..

  5. Impossible to load an image in xcassets on bundle

    Impossible to load an image in xcassets on bundle up vote5down votefavorite 3 I need to include imag ...

  6. 安装go语言,配置环境及IDE,只需3步

    安装go语言,配置环境及IDE,只需3步 ( 欢迎加入go语言群: 218160862 , 群内有实践) 第1.下载 go压缩包,解压   ,如果你是window系统,请选择go1.5.windows ...

  7. windows下Bullet 2.82编译安装(Bullet Physics开发环境配置)

    平台:Win7,VS2010 1. Bullet库的组织 下图是Bullet_User_Manual中的截图: 从中可见,Bullet的LinearMath(线性数学模块),其上是BulletColl ...

  8. 使用Quartz.net动态设置定时时间问题

    关于使用Quartz.net就不用解释了.. 应客户需求问题..需要将做一个界面设置定时的时间.因此我在百度一番..用CronExpression类可以设置时间... 我知道这个类有定义好的字段..不 ...

  9. SpringMVC中使用Cron表达式的定时器

    SpringMVC中使用Cron表达式的定时器 cron(定时策略)简要说明 顺序: 秒 分 时 日 月 星期 年份 (7个参数,空格隔开各个参数,年份非必须参数) 通配符: , 如果分钟位置为* 1 ...

  10. php学习前的准备

    1.用户文档: 官方中文文档:http://www.php.net/manual/zh/ 官方扩展库:http://pecl.php.net/packages.php