Skip to content

Commit 7237bea

Browse files
committed
fix(build): Handle namespace packages for PyPI CUDA detection
The nvidia package from PyPI (e.g., nvidia-nccl-cu12/cu13) is a PEP 420 namespace package that doesn't have __file__ attribute. This caused get_cuda_include_dirs() to fail with TypeError when building with only NCCL from PyPI. Use nvidia.__path__[0] which works for both namespace packages and regular packages. Fixes: #2331 Signed-off-by: Santosh Bhavani <santosh.bhavani@live.com>
1 parent 5f0e3b9 commit 7237bea

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

build_tools/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,13 @@ def get_cuda_include_dirs() -> Tuple[str, str]:
239239
except ModuleNotFoundError as e:
240240
raise RuntimeError("CUDA not found.")
241241

242-
cuda_root = Path(nvidia.__file__).parent
242+
# Handle namespace packages (PEP 420) which don't have __file__
243+
# The nvidia package from PyPI CUDA packages is a namespace package
244+
if hasattr(nvidia, "__path__") and nvidia.__path__:
245+
cuda_root = Path(list(nvidia.__path__)[0])
246+
else:
247+
raise RuntimeError("Could not locate nvidia package directory.")
248+
243249
return [
244250
subdir / "include"
245251
for subdir in cuda_root.iterdir()

0 commit comments

Comments
 (0)