RuntimeError:即使在 pip install ninja 之后,Ninja 也需要加载 C++ 扩展

我正在尝试使用 Torch 运行我的 DL 模型。在运行时,我遇到了这个错误:

UserWarning: Just-in-time loading and compiling the CUDA kernels of SRU was unsuccessful. Got the following error:
Ninja is required to load C++ extensions
  warnings.warn("Just-in-time loading and compiling the CUDA kernels of SRU was unsuccessful. "
Traceback (most recent call last):
  File "/home/.../.local/lib/python3.8/site-packages/sru/cuda_functional.py", line 15, in <module>
    load(
  File ""/home/.../.local/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1080, in load
    return _jit_compile(
  File ""/home/.../.local/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1293, in _jit_compile
    _write_ninja_file_and_build_library(
  File ""/home/.../.local/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1374, in _write_ninja_file_and_build_library
    verify_ninja_availability()
  File ""/home/.../.local/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1430, in verify_ninja_availability
    raise RuntimeError("Ninja is required to load C++ extensions")
RuntimeError: Ninja is required to load C++ extensions

During handling of the above exception, another exception occurred:

现在,显而易见的解决方案是 pip install ninja 但是,它表明 ninja 已经安装/

有人能帮我吗?

stack overflow RuntimeError: Ninja is required to load C++ extensions even after pip install ninja
原文答案

答案:

作者头像

conda install ninja 对我有用。作为pip安装ninja版本1.10,conda安装ninja版本是1.7。我想这是关于路径的问题