Python error: Unable to find vcvarsall.bat
在安装一些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 进行安装
Python error: Unable to find vcvarsall.bat的更多相关文章
- [转]Resolving Python error: Unable to find vcvarsall.bat
Resolving Python error: Unable to find vcvarsall.bat While installing python package flask-user usin ...
- windows上,python安装非官方包,提示error: Unable to find vcvarsall.bat
在windows机器上安装python非官方包,如果环境只是用于开发,不作任何测试的话,最好的解决办法是: 在Linux上pip安装好之后,把python根目录lib/python3.6/site-p ...
- 【转】Windows下Python快速解决error: Unable to find vcvarsall.bat
转自:http://blog.csdn.net/sad_sugar/article/details/73743863 系统配置:Windows10 x64, Visual Studio 2017, P ...
- error: Unable to find vcvarsall.bat
http://www.crifan.com/python_mmseg_error_unable_to_find_vcvarsall_bat/ [已解决]安装Python模块mmseg出错:error: ...
- 在windows下安装lxml 报错error: Unable to find vcvarsall.bat
刚开始安装 ,我是使用命令pip install lxml直接进行安装,不过出错了 error: Unable to find vcvarsall.bat 解决方案: 1.首先安装wheel,pip ...
- 解决 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 错误,看到这个 ...
- python27(32位)安装模块报错“error: Unable to find vcvarsall.bat”
1)首先,下载一个Microsoft Visual C++ Compiler for Python 2.7的补丁,下载地址在这里: http://www.microsoft.com/en-us/dow ...
- error: Setup script exited with error: Unable to find vcvarsall.bat
安装mxnet python版本时遇到“Unable to find vcvarsall.bat”错误搜索一下后查到如下方法: python 3.5.2版本依赖高版本的vs解决办法是安装vs2015的 ...
- pip安装scrapy时报错:error: Unable to find vcvarsall.bat
网上一堆胡说八道的,请看微软官方文章: https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcv ...
随机推荐
- 修改HTTPD.CONF中的DocumentRoot,出现 You don't have permission to access /??? on this server.
apache 2.4 修改/conf/extra/httpd-vhosts.conf <VirtualHost _default_:80> DocumentRoot '${SRVROOT} ...
- Maven项目下java.lang.ClassNotFoundException的解决方法
问题背景: Maven的project下,项目中已经引用了相应的jar包.Java class中没有语法错误,在执行时报ClassNotFound.检查了Maven的pom.xml,依赖引入正常. 错 ...
- OD调试16
今天还是15的那个程序,但是呢,换一种方法去掉NAG窗口 用OD载入,暂停,查看调用的堆栈 先看最后一个 查看调用,下断点 往上看看,找到入口的地方,设下断.点,重载,运行,单步 通过单步发现 ...
- iOS—Mask属性的使用
Mask属性介绍 Mask平时用的最多的是masksToBounds 吧. 其实除此以外Mask使用场景很多,看完之后你会发现好真是好用的不要不要的... 先来了解下Mask属性到底是什么? Mask ...
- 运算符 与 分支语句:if ,else if,else;switch case
分支语句: if else if else : switch case --如何使用 if else if else: Console. ...
- RaspBMC使用攻略与问题总结
XBMC最初叫Xbox Media Center,是xbox的游戏控制器,后来移植到其他操作系统 XBMC在v14后改名为Kodi RaspBMC是XBMC在Rasperry PI上定制的linux发 ...
- 浅谈GPU
Programmable Graphics Processing Unit(GPU),可编程图形处理单元,可编程图形硬件. 98年NVIDIA的modern GPU研发成功,使用晶体管(transis ...
- WKWebView比UIWebView优越性
1.在使用两者的过程中发现前者比后者节省内存一倍多,WKWebView 是苹果在 iOS 8 中引入的新组件,目的是给出一个新的高性能的 Web View 解决方案,摆脱过去 UIWebView 的老 ...
- POJ 3009 DFS+剪枝
POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Acce ...
- CGRectInset & CGRectOffset
1.CGRectInset CGRect CGRectInset ( CGRect rect, CGFloat dx, CGFloat dy);以原rect为中心,再参考dx,dy,进行缩 ...