簡單解決python安裝中的Unable to find vcvarsall.bat問題


使用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的原文如下:

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

修改為:

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判斷),保存后重新安裝


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM