pytorch c++混编报错 Error checking compiler version for cl: [WinError 2] 系统找 不到指定的文件。

1.报错信息

(python37) H:\emd>python setup.py install
running install
running bdist_egg
running egg_info
creating emd.egg-info
writing emd.egg-info\PKG-INFO
writing dependency_links to emd.egg-info\dependency_links.txt
writing top-level names to emd.egg-info\top_level.txt
writing manifest file 'emd.egg-info\SOURCES.txt'
 D:\Anaconda_app\envs\python37\lib\site-packages\torch\utils\cpp_extension.py:370: UserWarning: Attempted to use ninja as the BuildExtension backend but we
could not find ninja.. Falling back to using the slow distutils backend. 
  warnings.warn(msg.format('we could not find ninja.'))
reading manifest file 'emd.egg-info\SOURCES.txt'
writing manifest file 'emd.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_ext
D:\Anaconda_app\envs\python37\lib\site-packages\torch\utils\cpp_extension.py:305: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找
不到指定的文件。
  warnings.warn(f'Error checking compiler version for {compiler}: {error}')
building 'emd' extension
creating build
creating build\temp.win-amd64-3.7
……
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(427): note: 参见对正在编译的类 模板 实例化“OptionalBase”的
引用
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\ATen/core/TensorBody.h(734): note: 参见对正在编译的类 模板 实例化“c10::optional
”的引用
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(395): warning C4624: “c10::trivially_copyable_optimization_optional_base
”: 已将析构函数隐式定义为“已删除”
        with
        [
            T=at::Tensor
        ]
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(476): warning C4814: “c10::optional::contained_val”: 在 C++
14 中,"constexpr" 将不表示“常量”;请考虑显式指定“常量”
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): error C2556: “at::Tensor &c10::optional::contained_val
(void) const &”: 重载函数与“const at::Tensor &c10::optional::contained_val(void) const &”只是在返回类型上不同
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(471): note: 参见“c10::optional::contained_val”的声明
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): error C2373: “c10::optional::contained_val”: 重定义;
不同的类型修饰符
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(471): note: 参见“c10::optional::contained_val”的声明
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(476): warning C4814: “c10::optional::contained_val”: 在 C++14
中,"constexpr" 将不表示“常量”;请考虑显式指定“常量”
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\ATen/core/TensorBody.h(774): note: 参见对正在编译的类 模板 实例化“c10::optional”的
引用
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): error C2556: “int64_t &c10::optional::contained_val(void)
 const &”: 重载函数与“const int64_t &c10::optional::contained_val(void) const &”只是在返回类型上不同
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(471): note: 参见“c10::optional::contained_val”的声明
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): error C2373: “c10::optional::contained_val”: 重定义;不
同的类型修饰符
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(471): note: 参见“c10::optional::contained_val”的声明
D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): fatal error C1003: 错误计数超过 100;正在停止编译
error: command 'D:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2


2.错误分析

分析:从以上报错信息里面,得到信息
D:\Anaconda_app\envs\python37\lib\site-packages\torch\utils\cpp_extension.py:370: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja… Falling back to using the slow distutils backend.

D:\Anaconda_app\envs\python37\lib\site-packages\torch\utils\cpp_extension.py:305: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找
不到指定的文件。warnings.warn(f’Error checking compiler version for {compiler}: {error}’)

1)需要用到ninja包来编译,但是我没有装ninja,所以需要先装ninja(pip install ninja)
2) 找不到符合要求版本的cl.exe,根据给出的D:\Anaconda_app\envs\python37\lib\site-packages\torch\utils\cpp_extension.py:305:
跳到源码

    try:
        if sys.platform.startswith('linux'):
            minimum_required_version = MINIMUM_GCC_VERSION
            versionstr = subprocess.check_output([compiler, '-dumpfullversion', '-dumpversion'])
            version = versionstr.decode().strip().split('.')
        else:
            minimum_required_version = MINIMUM_MSVC_VERSION
            compiler_info = subprocess.check_output(compiler, stderr=subprocess.STDOUT)
            match = re.search(r'(\d+)\.(\d+)\.(\d+)', compiler_info.decode().strip())
            version = (0, 0, 0) if match is None else match.groups()
    except Exception:
        _, error, _ = sys.exc_info()
        warnings.warn(f'Error checking compiler version for {compiler}: {error}')
        return False

我不是在linux平台,而是win平台,于是找到cl.exe的版本要求:

MINIMUM_MSVC_VERSION = (19, 0, 24215)

MSVC是一个编译器,其编译器名字叫"cl.exe",它是微软专为VS开发的一款编译器。

上面语句写了 MSVC 最低的版本要求MSVC 19.0.24215.

3.需要了解的知识

_MSC_VER 是MSVC编译器的内置宏,定义了编译器的版本。
MS Microsoft 的简写。
C MSC 就是 Microsoft 的 C 编译器。
VER Version 的简写。

因此_MSC_VER的意思就是:Microsoft 的 C 编译器的版本。

MSC    1.0   _MSC_VER == 100
MSC    2.0   _MSC_VER == 200
MSC    3.0   _MSC_VER == 300
MSC    4.0   _MSC_VER == 400
MSC    5.0   _MSC_VER == 500
MSC    6.0   _MSC_VER == 600
MSC    7.0   _MSC_VER == 700
MSVC++ 1.0   _MSC_VER == 800
MSVC++ 2.0   _MSC_VER == 900
MSVC++ 4.0   _MSC_VER == 1000 (Developer Studio 4.0)
MSVC++ 4.2   _MSC_VER == 1020 (Developer Studio 4.2)
MSVC++ 5.0   _MSC_VER == 1100 (Visual Studio 97 version 5.0)
MSVC++ 6.0   _MSC_VER == 1200 (Visual Studio 6.0 version 6.0)
MSVC++ 7.0   _MSC_VER == 1300 (Visual Studio .NET 2002 version 7.0)
MSVC++ 7.1   _MSC_VER == 1310 (Visual Studio .NET 2003 version 7.1)
MSVC++ 8.0   _MSC_VER == 1400 (Visual Studio 2005 version 8.0)
MSVC++ 9.0   _MSC_VER == 1500 (Visual Studio 2008 version 9.0)
MSVC++ 10.0  _MSC_VER == 1600 (Visual Studio 2010 version 10.0)
MSVC++ 11.0  _MSC_VER == 1700 (Visual Studio 2012 version 11.0)
MSVC++ 12.0  _MSC_VER == 1800 (Visual Studio 2013 version 12.0)
MSVC++ 14.0  _MSC_VER == 1900 (Visual Studio 2015 version 14.0)
MSVC++ 14.1  _MSC_VER == 1910 (Visual Studio 2017 version 15.0)
MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)
MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)
MSVC++ 14.2  _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
MSVC++ 14.21 _MSC_VER == 1921 (Visual Studio 2019 Version 16.1)
MSVC++ 14.22 _MSC_VER == 1922 (Visual Studio 2019 Version 16.2)

例如: MSVC++ 14.0 表示 Visual C++ 的版本为 14.0,后面括号中的 Visual Studio 2015,表明该 VC++ 包含在微软开发工具 Visual Studio 2015 中。

参考:MSVC编译器中的_MSC_VER如何使用?

4.回顾问题及解决

1)ninja已安装
2)对比第三部分中的表,我至少要安装VS2017,但是电脑中VS版本是2015,卸载重装。(也有小伙伴没有卸载直接重装也行的,个人习惯卸载重装)
VS2015完全卸载:利用TotalUninstaller彻底卸载Visual Studio2013、2015
VS2017安装:VS2017下载地址和安装教程(图解)

超级推荐上面链接中的VS2017下载方式,有个简体中文版的安装引导程序,很方便~

你可能感兴趣的:(python,正则表达式,后端)