解决一次error: Unable to find vcvarsall.bat的经历
2017-05-21 10:39
513 查看
在使用cx_freeze做window软件打包时,碰到了error: Unable to find vcvarsall.bat,然而这才是蛋疼的开始,经过一轮“百度”后,最终找到了一个自认为能解决的方案(基于python2.7+win7_x64),其他版本,不能保证哈,但估计思路差不多,敬请诸君参考!
1. 为什么会出现该错误,好吧,先扒扒Python的代码
定位到该文件:Python27\Lib\distutils\msvc9compiler.py(看自己的Python安装路径)
以上的代码可以看出,python是通过注册表的形式去定位到“vcvarsall.bat”这大哥所在路径的。所以我又特意把路径打印出来,如下:
VS90COMNTOOLS productdir: None Software\Microsoft\VCExpress\9.0
很明显我的目前的路径为空哈。。。。。几百个草泥马奔跑过!
当你看到VCExpress时,是不是觉得要去安装这个了?其实还是可以通过安装一个专门针对Python2.7的报,路径为:https://www.microsoft.com/en-us/download/details.aspx?id=44266
当你开心的安装好了,然后你觉得大功告成,然并卵,因为这个安装好,并不会自动帮你在注册表里登记哈。。。而且他还要安装在用户目录,所以只能通过搜索vcvarsall.bat位置,以下是我的路径:
C:\Users\username\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
怎么解决,人肉加上呗:
错误原因:
报这个错误的原因是Python的distutils模块中的msvc9compiler.py并不从环境变量指定的路径中寻找’vcvarsall.bat’,而是通过注册表来寻找…,然而,不知为什么编译器安装过程没有配置注册表。
解决办法:
只要手工把注册表配置好,就可以了。
// 1、打开注册表编辑器
run regedit
// 2、配置
// 2.1、如果你安装的Python是32位的,则,创建如下项:
// 2.2、如果你安装的Python是64位的,则,创建如下项:
// 3、并在此项下新建字符串值:
名称:
数据:vcvarsall.bat所在路径
注意:路径中不包含最后的反斜杠。
此处解决方案有:
http://stackoverflow.com/questions/6551724/how-do-i-point-easy-install-to-vcvarsall-bat http://blog.csdn.net/donger_soft/article/details/44838109
1. 为什么会出现该错误,好吧,先扒扒Python的代码
定位到该文件:Python27\Lib\distutils\msvc9compiler.py(看自己的Python安装路径)
def find_vcvarsall(version): """Find the vcvarsall.bat file At first it tries to find the productdir of VS 2008 in the registry. If that fails it falls back to the VS90COMNTOOLS env var. """ vsbase = VS_BASE % version try: productdir = Reg.get_value(r"%s\Setup\VC" % vsbase, "productdir") print 'productdir', productdir, 'vsbase:', vsbase except KeyError: productdir = None # trying Express edition if productdir is None: vsbase = VSEXPRESS_BASE % version try: productdir = Reg.get_value(r"%s\Setup\VC" % vsbase, "productdir") except KeyError: productdir = None log.debug("Unable to find productdir in registry") if not productdir or not os.path.isdir(productdir): toolskey = "VS%0.f0COMNTOOLS" % version print 'toolskey', toolskey, 'productdir:', productdir, vsbase toolsdir = os.environ.get(toolskey, None) if toolsdir and os.path.isdir(toolsdir): productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC") productdir = os.path.abspath(productdir) if not os.path.isdir(productdir): log.debug("%s is not a valid directory" % productdir) return None else: log.debug("Env var %s is not set or invalid" % toolskey)
以上的代码可以看出,python是通过注册表的形式去定位到“vcvarsall.bat”这大哥所在路径的。所以我又特意把路径打印出来,如下:
VS90COMNTOOLS productdir: None Software\Microsoft\VCExpress\9.0
很明显我的目前的路径为空哈。。。。。几百个草泥马奔跑过!
当你看到VCExpress时,是不是觉得要去安装这个了?其实还是可以通过安装一个专门针对Python2.7的报,路径为:https://www.microsoft.com/en-us/download/details.aspx?id=44266
当你开心的安装好了,然后你觉得大功告成,然并卵,因为这个安装好,并不会自动帮你在注册表里登记哈。。。而且他还要安装在用户目录,所以只能通过搜索vcvarsall.bat位置,以下是我的路径:
C:\Users\username\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0
怎么解决,人肉加上呗:
错误原因:
报这个错误的原因是Python的distutils模块中的msvc9compiler.py并不从环境变量指定的路径中寻找’vcvarsall.bat’,而是通过注册表来寻找…,然而,不知为什么编译器安装过程没有配置注册表。
解决办法:
只要手工把注册表配置好,就可以了。
// 1、打开注册表编辑器
run regedit
// 2、配置
// 2.1、如果你安装的Python是32位的,则,创建如下项:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Setup\VC
// 2.2、如果你安装的Python是64位的,则,创建如下项:
HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC
// 3、并在此项下新建字符串值:
名称:
productdir
数据:vcvarsall.bat所在路径
注意:路径中不包含最后的反斜杠。
此处解决方案有:
http://stackoverflow.com/questions/6551724/how-do-i-point-easy-install-to-vcvarsall-bat http://blog.csdn.net/donger_soft/article/details/44838109
相关文章推荐
- error: Setup script exited with error: Unable to find vcvarsall.bat解决办法
- 对于解决python安装第三方包时候,报错 error: Unable to find vcvarsall.bat的终极秘诀
- 关于python下构建c模块出现error: Unable to find vcvarsall.bat问题的解决方法
- pip install scrapy报错:error: Unable to find vcvarsall.bat解决方法
- Scrapy安装出错:error: Unable to find vcvarsall.bat的解决方法
- [问题解决][error: unable to find vcvarsall.bat]
- 彻底解决 error: Unable to find vcvarsall.bat
- Win7 64位编译Python扩展解决”error: Unable to find vcvarsall.bat”问题
- 转:python 3.4 error: Microsoft Visual C++ 10.0 is required(Unable to find vcvarsall.bat)解决办法,自研亲测可行
- [Python3.5]解决安装一些模块时出现“error: Unable to find vcvarsall.bat”的错误
- easy_install和pip安装模块,提示error: Unable to find vcvarsall.bat的解决方法
- 转载:彻底解决 error: Unable to find vcvarsall.bat
- error: Unable to find vcvarsall.bat 解决方法
- 解决 error: Unable to find vcvarsall.bat
- easy_install 错误Setup script exited with error: Unable to find vcvarsall.bat解决方法
- 彻底解决 error: Unable to find vcvarsall.bat
- python安装第三方库,报“error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat).”错误,解决办法
- Python3 pip 解决问题: error: Unable to find vcvarsall.bat
- [转]彻底解决 error: Unable to find vcvarsall.bat
- 【已解决】Scrapy安装出错:error: Unable to find vcvarsall.bat的解决方法