CUDA nvcc Compiler (CUDA 12)
The `nvidia-cuda-nvcc-cu12` package provides the NVIDIA CUDA C/C++ compiler (`nvcc`) as a Python wheel for CUDA Toolkit version 12. It enables Python-based build systems and projects (e.g., those using PyTorch, Numba, or CuPy for custom CUDA kernels) to access the `nvcc` executable for compiling CUDA code. This package is part of NVIDIA's initiative to streamline CUDA toolkit component installation via `pip`, aiming for better portability and compatibility within the Python ecosystem. The current version is 12.9.86, and NVIDIA typically updates CUDA versions with new GPU architectures, alongside quarterly minor releases.
Warnings
- gotcha This package primarily provides the `nvcc` *compiler executable* on your system's PATH, rather than a Python library with direct `import`able modules. Python projects interact with `nvcc` by invoking it as an external process (e.g., via `subprocess` calls or through framework-specific build extensions like PyTorch's `CUDAExtension`).
- gotcha Installing `nvidia-cuda-nvcc-cu12` via `pip` delivers the `nvcc` compiler and associated tools, but it does *not* install the NVIDIA GPU driver. A compatible and correctly installed NVIDIA GPU driver is a separate, fundamental prerequisite for using CUDA-enabled applications and for `nvcc` to function correctly.
- breaking While CUDA follows semantic versioning, ensuring compatibility between different CUDA Toolkit components (such as `nvcc`, `nvrtc`, `nvjitlink`, and various CUDA libraries like `cuBLAS`, `cuFFT`) is critical. Especially for features like Link Time Optimization (LTO), all components should ideally come from the same major and minor CUDA release family to avoid unexpected issues.
- breaking CUDA 13.0 (a successor to CUDA 12.x) introduces significant changes to `nvcc`'s handling of ELF visibility and linkage for `__global__` functions and device variables. These changes can impact separate compilation models and require attention when migrating custom CUDA kernels.
Install
-
pip install nvidia-cuda-nvcc-cu12
Imports
- nvcc
This package provides the `nvcc` executable on the system's PATH. It is not a Python module with direct `import` statements.
Quickstart
import subprocess
import os
try:
# Attempt to run nvcc --version to verify installation
result = subprocess.run(['nvcc', '--version'], capture_output=True, text=True, check=True)
print("nvcc is installed and accessible:")
print(result.stdout)
except FileNotFoundError:
print("Error: nvcc command not found. Ensure it's in your system's PATH.")
except subprocess.CalledProcessError as e:
print(f"Error running nvcc: {e}")
print(f"Stderr: {e.stderr}")
except Exception as e:
print(f"An unexpected error occurred: {e}")