实际上有一个似乎是更常见的报错为Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/。在这个文章中我会分析这个信息的发生过程(虽然主要篇幅实际上在上一篇文章)。
def_msvc14_get_vc_env(plat_spec): """Python 3.8 "distutils/_msvccompiler.py" backport""" if"DISTUTILS_USE_SDK"in environ: return { key.lower(): value for key, value in environ.items() }
defmsvc14_get_vc_env(plat_spec): """ Patched "distutils._msvccompiler._get_vc_env" for support extra Microsoft Visual C++ 14.X compilers. Set environment without use of "vcvarsall.bat". Parameters ---------- plat_spec: str Target architecture. Return ------ dict environment """
# Always use backport from CPython 3.8 try: return _msvc14_get_vc_env(plat_spec) except distutils.errors.DistutilsPlatformError as exc: _augment_exception(exc, 14.0) raise
def_augment_exception(exc, version, arch=''): """ Add details to the exception message to help guide the user as to what action will resolve it. """ # Error if MSVC++ directory not found or environment not set message = exc.args[0]
if"vcvarsall"in message.lower() or"visual c"in message.lower(): # Special error message if MSVC++ not installed tmpl = 'Microsoft Visual C++ {version:0.1f} or greater is required.' message = tmpl.format(**locals()) msdownload = 'www.microsoft.com/download/details.aspx?id=%d' if version == 9.0: if arch.lower().find('ia64') > -1: # For VC++ 9.0, if IA64 support is needed, redirect user # to Windows SDK 7.0. # Note: No download link available from Microsoft. message += ' Get it with "Microsoft Windows SDK 7.0"' else: # For VC++ 9.0 redirect user to Vc++ for Python 2.7 : # This redirection link is maintained by Microsoft. # Contact vspython@microsoft.com if it needs updating. message += ' Get it from http://aka.ms/vcpython27' elif version == 10.0: # For VC++ 10.0 Redirect user to Windows SDK 7.1 message += ' Get it with "Microsoft Windows SDK 7.1": ' message += msdownload % 8279 elif version >= 14.0: # For VC++ 14.X Redirect user to latest Visual C++ Build Tools message += (' Get it with "Microsoft C++ Build Tools": ' r'https://visualstudio.microsoft.com' r'/visual-cpp-build-tools/')
exc.args = (message, )
通过简单的查看,我们可以发现这个函数可能会raise一个错误,信息为Microsoft Visual C++ {version:0.1f} or greater is required.或者就我所知更为常见的Microsoft Visual C++ 14.0 or greater is required.
进入msvc14_get_vc_env包装函数,检查这个过程中是否有raise distutils.errors.DistutilsPlatformError,有的话就捕获并调用_augment_exception函数。 4.进入_augment_exception函数进行错误处理,然后就获得了非常心脏骤停的Microsoft Visual C++ 14.0 or greater is required.