• Error checking compiler version for cl: [WinError 2] 系统找 不到指定的文件[已解决]


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

    win11 pytorch 进行C++编译时出现错误

    1. (python37) H:\emd>python setup.py install
    2. running install
    3. running bdist_egg
    4. running egg_info
    5. creating emd.egg-info
    6. writing emd.egg-info\PKG-INFO
    7. writing dependency_links to emd.egg-info\dependency_links.txt
    8. writing top-level names to emd.egg-info\top_level.txt
    9. writing manifest file 'emd.egg-info\SOURCES.txt'
    10. 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
    11. could not find ninja.. Falling back to using the slow distutils backend.
    12. warnings.warn(msg.format('we could not find ninja.'))
    13. reading manifest file 'emd.egg-info\SOURCES.txt'
    14. writing manifest file 'emd.egg-info\SOURCES.txt'
    15. installing library code to build\bdist.win-amd64\egg
    16. running install_lib
    17. running build_ext
    18. D:\Anaconda_app\envs\python37\lib\site-packages\torch\utils\cpp_extension.py:305: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找
    19. 不到指定的文件。
    20. warnings.warn(f'Error checking compiler version for {compiler}: {error}')
    21. building 'emd' extension
    22. creating build
    23. creating build\temp.win-amd64-3.7
    24. ……
    25. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(427): note: 参见对正在编译的类 模板 实例化“OptionalBase<at::Tensor>”的
    26. 引用
    27. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\ATen/core/TensorBody.h(734): note: 参见对正在编译的类 模板 实例化“c10::optional<at::Tensor>
    28. ”的引用
    29. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(395): warning C4624: “c10::trivially_copyable_optimization_optional_base
    30. <T>”: 已将析构函数隐式定义为“已删除”
    31. with
    32. [
    33. T=at::Tensor
    34. ]
    35. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(476): warning C4814: “c10::optional<at::Tensor>::contained_val”: 在 C++
    36. 14 中,"constexpr" 将不表示“常量”;请考虑显式指定“常量”
    37. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): error C2556: “at::Tensor &c10::optional<at::Tensor>::contained_val
    38. (void) const &”: 重载函数与“const at::Tensor &c10::optional<at::Tensor>::contained_val(void) const &”只是在返回类型上不同
    39. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(471): note: 参见“c10::optional<at::Tensor>::contained_val”的声明
    40. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): error C2373: “c10::optional<at::Tensor>::contained_val”: 重定义;
    41. 不同的类型修饰符
    42. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(471): note: 参见“c10::optional<at::Tensor>::contained_val”的声明
    43. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(476): warning C4814: “c10::optional<int64_t>::contained_val”: 在 C++14
    44. 中,"constexpr" 将不表示“常量”;请考虑显式指定“常量”
    45. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\ATen/core/TensorBody.h(774): note: 参见对正在编译的类 模板 实例化“c10::optional<int64_t>”的
    46. 引用
    47. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): error C2556: “int64_t &c10::optional<int64_t>::contained_val(void)
    48. const &”: 重载函数与“const int64_t &c10::optional<int64_t>::contained_val(void) const &”只是在返回类型上不同
    49. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(471): note: 参见“c10::optional<int64_t>::contained_val”的声明
    50. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): error C2373: “c10::optional<int64_t>::contained_val”: 重定义;不
    51. 同的类型修饰符
    52. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(471): note: 参见“c10::optional<int64_t>::contained_val”的声明
    53. D:\Anaconda_app\envs\python37\lib\site-packages\torch\include\c10/util/Optional.h(477): fatal error C1003: 错误计数超过 100;正在停止编译
    54. error: command 'D:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

    关键错误 1.:UserWarning: Error checking compiler version for cl: [WinError 2] 系统找
    不到指定的文件。

    定位位置:D:\Anaconda_app\envs\python37\lib\site-packages\torch\utils\cpp_extension.py:305行

    看看这个地方怎么有错误:

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

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

    MINIMUM_MSVC_VERSION = (19, 0, 24215)# 这个在程序里面,txt文件打开,选定它,通过查找可以找到这个地方。

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

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

    MSC_VER的意思就是:Microsoft 的 C 编译器的版本

    1. MSC 1.0 _MSC_VER == 100
    2. MSC 2.0 _MSC_VER == 200
    3. MSC 3.0 _MSC_VER == 300
    4. MSC 4.0 _MSC_VER == 400
    5. MSC 5.0 _MSC_VER == 500
    6. MSC 6.0 _MSC_VER == 600
    7. MSC 7.0 _MSC_VER == 700
    8. MSVC++ 1.0 _MSC_VER == 800
    9. MSVC++ 2.0 _MSC_VER == 900
    10. MSVC++ 4.0 _MSC_VER == 1000 (Developer Studio 4.0)
    11. MSVC++ 4.2 _MSC_VER == 1020 (Developer Studio 4.2)
    12. MSVC++ 5.0 _MSC_VER == 1100 (Visual Studio 97 version 5.0)
    13. MSVC++ 6.0 _MSC_VER == 1200 (Visual Studio 6.0 version 6.0)
    14. MSVC++ 7.0 _MSC_VER == 1300 (Visual Studio .NET 2002 version 7.0)
    15. MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio .NET 2003 version 7.1)
    16. MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005 version 8.0)
    17. MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008 version 9.0)
    18. MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010 version 10.0)
    19. MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012 version 11.0)
    20. MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013 version 12.0)
    21. MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015 version 14.0)
    22. MSVC++ 14.1 _MSC_VER == 1910 (Visual Studio 2017 version 15.0)
    23. MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
    24. MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
    25. MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
    26. MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)
    27. MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
    28. MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)
    29. MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
    30. MSVC++ 14.21 _MSC_VER == 1921 (Visual Studio 2019 Version 16.1)
    31. MSVC++ 14.22 _MSC_VER == 1922 (Visual Studio 2019 Version 16.2)

    注意这是它要求的最低版本,如果你安装vs2019,2022,在安装的地方有cl.exe。需要搜索一下,然后把cl.exe所在的路径添加到系统环境变量中,也就是path中,别忘了重启电脑。问题解决

    第一步解决。

    错误 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.
     

    没有安装 ninja...。这个ninja是什么东东,这里不管一会安装上就行

    如何安装ninja

    pip install ninja

    运行结果

    1. Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
    2. Collecting ninja
    3. Downloading ninja-1.11.1-py2.py3-none-win_amd64.whl (313 kB)
    4. |████████████████████████████████| 313 kB 939 kB/s
    5. Installing collected packages: ninja
    6. Successfully installed ninja-1.11.1

  • 相关阅读:
    如何使用mysqldump快速复制Mysql数据库操作实践
    maven环境配置
    android 全屏FullScreen的配置
    MATLAB程序设计课后作业三、四
    【数据库】拼接字段 使用别名
    golang将pcm格式音频转为mp3格式
    分享一种非隔离控制三象限双向可控硅的产品级电路
    认识微服务
    离线密码破解(1)
    springboot 学习十一:Spring Boot 优雅的集成 Lombok
  • 原文地址:https://blog.csdn.net/Vertira/article/details/128088045