# 运行时错误：NVRTC 编译失败：错误：无法打开源文件 'cuda_runtime.h'

- **ID:** `cuda/nvrtc-include-path-missing`
- **领域:** cuda
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

NVRTC（CUDA 运行时编译）找不到 CUDA 包含路径，因为 CUDA 工具包头文件不在默认搜索路径中，或者 CUDA_HOME 环境变量未正确设置。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CUDA 11.8 | active | — | — |
| CUDA 12.0 | active | — | — |
| PyTorch 2.1 | active | — | — |
| TensorFlow 2.13 | active | — | — |

## 解决方案

1. ```
   Set the CUDA_HOME environment variable to the root of your CUDA installation (e.g., /usr/local/cuda-12.1) before running the script. For Python, add it in the code using os.environ.
   ```
2. ```
   Create a symlink from the CUDA toolkit include directory to a standard location, or add it to the CPLUS_INCLUDE_PATH environment variable.
   ```

## 无效尝试

- **** — NVRTC relies on the system's CUDA installation, not the deep learning framework's bundled headers; reinstalling the framework does not fix the include path. (90% 失败率)
- **** — This may work temporarily but breaks portability and version compatibility; also other headers may be missing. (70% 失败率)
