NVIDIA CUDA NVCC Compiler
raw JSON → 13.2.78 verified Fri May 01 auth: no python
Provides the nvcc CUDA compiler as a Python package for building CUDA kernels. Version 13.2.78 corresponds to CUDA 12.8. This package bundles the nvcc compiler and dependencies, simplifying CUDA compilation in Python environments without requiring a system CUDA installation.
pip install nvidia-cuda-nvcc Common errors
error ModuleNotFoundError: No module named 'nvidia.cuda' ↓
cause Missing or incorrect import path. The package `nvidia-cuda-nvcc` must be installed, and the import path changed after version 12.
fix
Run
pip install nvidia-cuda-nvcc and use from nvidia.cuda.nvcc import nvcc_path. error RuntimeError: nvcc not found. Set CUDA_HOME or ensure nvcc is on PATH. ↓
cause Calling subprocess with 'nvcc' without using the bundled path. The system may lack a CUDA installation.
fix
Use
nvcc_path() from the package to get the correct path and pass it to subprocess. error FileNotFoundError: [Errno 2] No such file or directory: 'nvcc' ↓
cause Similar to above: nvcc is not on PATH. The package's bin directory is not automatically added.
fix
Use
from nvidia.cuda.nvcc import nvcc_path; nvcc = nvcc_path() and then subprocess.run([nvcc, ...]). Warnings
breaking The package name and import structure changed in version 12.x. Previously, the package was installed as `cuda-nvcc` with import `cuda.cc.nvcc`. Now it's `nvidia-cuda-nvcc` with import `nvidia.cuda.nvcc`. Old imports will break. ↓
fix Update import to `from nvidia.cuda.nvcc import nvcc_path` and install the new package.
gotcha The nvcc binary is bundled inside the Python package and not added to PATH. You must use `nvcc_path()` or call it via subprocess; calling `nvcc` directly from shell will not work unless you manually add the package's bin directory to PATH. ↓
fix Always use `from nvidia.cuda.nvcc import nvcc_path` to get the path, then invoke via subprocess.
deprecated Some older versions used `from nvidia.cuda import nvcc` (without the .nvcc submodule). This still works in some versions but is deprecated and may be removed. ↓
fix Switch to explicit `from nvidia.cuda.nvcc import ...`.
Imports
- nvcc_path wrong
import nvcccorrectfrom nvidia.cuda.nvcc import nvcc_path - get_cc_version wrong
from nvidia.cuda.nvcc import cc_versioncorrectfrom nvidia.cuda.nvcc import get_cc_version
Quickstart
from nvidia.cuda.nvcc import nvcc_path
import subprocess
import os
# Get the path to the bundled nvcc
nvcc = nvcc_path()
print(f"Using nvcc at: {nvcc}")
# Simple compile and run a CUDA kernel
code = '''
__global__ void add(int *a, int *b, int *c) {
*c = *a + *b;
}
'''
with open('kernel.cu', 'w') as f:
f.write(code)
result = subprocess.run([nvcc, 'kernel.cu', '-o', 'kernel'], capture_output=True, text=True)
if result.returncode == 0:
print("Compilation succeeded")
else:
print("Compilation failed:", result.stderr)