前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >简单解决python安装中的Unable to find vcvarsall.bat问题

简单解决python安装中的Unable to find vcvarsall.bat问题

作者头像
charlieroro
发布2020-03-24 11:41:08
6640
发布2020-03-24 11:41:08
举报
文章被收录于专栏:charlierorocharlieroro

使用python36安装python的murmurhash的时候遇到上述问题,原因是没有找到vcvarsall.bat。查找vcvarsall.bat的方法是定义在_msvccompiler.py文件中的(注意该文件前面是有下划线的!),比如我本地的文件路径为"C:\Program Files\Python36\Lib\distutils\_msvccompiler.py“

打开该文件,修改函数_find_vcvarsall。我本地安装的是vs2017,vcvarsall.bat的路径为“E:\tools\vs2017\VC\Auxiliary\Build\vcvarsall.bat”

_find_vcvarsall的原文如下:

代码语言:javascript
复制
def _find_vcvarsall(plat_spec):
    try:
        key = winreg.OpenKeyEx(
            winreg.HKEY_LOCAL_MACHINE,
            r"Software\Microsoft\VisualStudio\SxS\VC7",
            access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
        )
    except OSError:
        log.debug("Visual C++ is not registered")
        return None, None

    with key:
        best_version = 0
        best_dir = None
        for i in count():
            try:
                v, vc_dir, vt = winreg.EnumValue(key, i)
            except OSError:
                break
            if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
                try:
                    version = int(float(v))
                except (ValueError, TypeError):
                    continue
                if version >= 14 and version > best_version:
                    best_version, best_dir = version, vc_dir
        if not best_version:
            log.debug("No suitable Visual C++ version found")
            return None, None

        vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
        if not os.path.isfile(vcvarsall):
            log.debug("%s cannot be found", vcvarsall)
            return None, None

        vcruntime = None
        vcruntime_spec = _VCVARS_PLAT_TO_VCRUNTIME_REDIST.get(plat_spec)
        if vcruntime_spec:
            vcruntime = os.path.join(best_dir,
                vcruntime_spec.format(best_version))
            if not os.path.isfile(vcruntime):
                log.debug("%s cannot be found", vcruntime)
                vcruntime = None

        return vcvarsall, vcruntime

修改为:

代码语言:javascript
复制
def _find_vcvarsall(plat_spec):
        best_dir = r'E:\tools\vs2017\VC\Auxiliary\Build'
        best_version = 17
        vcruntime = None
        vcruntime_spec = _VCVARS_PLAT_TO_VCRUNTIME_REDIST.get(plat_spec)
        if vcruntime_spec:
            vcruntime = os.path.join(best_dir,
                vcruntime_spec.format(best_version))
            if not os.path.isfile(vcruntime):
                log.debug("%s cannot be found", vcruntime)
                vcruntime = None
        print(vcruntime)
        return r'E:\tools\vs2017\VC\Auxiliary\Build\vcvarsall.bat', vcruntime

直接运行python安装即可。安装完后将该文件还原

如果遇到如下问题:

  • 找不到cl.exe

解决方法:将cl.exe的路径加入到系统环境变量path即可

  • mmh3module.cpp(9): error C2371: “int32_t”: 重定义;不同的基类型

解决办法:这个是因为int32_t的宏定义与其他地方重复,将mmh3module.cpp,murmur_hash_3.cpp,murmur_hash_3.hpp这三个文件中的int32_t全部替换为其他名称即可,比如int32_tA(或增加#ifndef判断),保存后重新安装

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-02-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档