You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Known issue: cuda.pathfinder cannot be imported in PEP 517 in-tree build backends without a workaround #1824
Packages that use cuda as a namespace package (e.g. cuda-bindings, cuda-core) and define an in-tree build backend via backend-path=["."] in pyproject.toml cannot import cuda.pathfinder at build time, even when cuda-pathfinder is listed in build-system.requires and correctly installed in the build environment.
Cause
When a PEP 517 build frontend (pip install, python -m build) loads an in-tree build backend, it prepends the project directory to sys.path. At that point, import cuda resolves the cuda namespace package to only the project's cuda/ subdirectory. Python caches a _NamespacePath for cuda in sys.modules. The cuda/pathfinder/ tree installed under site-packages is never merged into that namespace, so import cuda.pathfinder raises ModuleNotFoundError.
pkgutil.extend_path does not help: _NamespacePath._recalculate() re-derives its path list from the import machinery's finders, discarding manual additions.
Workaround
Replace the _NamespacePath with a plain list that includes the site-packages/cuda/ directory:
importosimportsysdef_import_get_cuda_path_or_home():
"""Import get_cuda_path_or_home, working around PEP 517 namespace shadowing. See https://github.com/NVIDIA/cuda-python/issues/1824 for why this helper is needed. """try:
importcuda.pathfinderexceptModuleNotFoundErrorasexc:
ifexc.namenotin ("cuda", "cuda.pathfinder"):
raisetry:
importcudaexceptModuleNotFoundError:
cuda=Noneforpinsys.path:
sp_cuda=os.path.join(p, "cuda")
ifos.path.isdir(os.path.join(sp_cuda, "pathfinder")):
cuda.__path__=list(cuda.__path__) + [sp_cuda]
breakelse:
raiseModuleNotFoundError(
"cuda-pathfinder is not installed in the build environment. ""Ensure 'cuda-pathfinder>=1.5' is in build-system.requires."
)
importcuda.pathfinderreturncuda.pathfinder.get_cuda_path_or_home
This pattern is used in both cuda_bindings/build_hooks.py and cuda_core/build_hooks.py. Any other package that uses cuda as a namespace and needs cuda.pathfinder at build time will need a similar workaround.
Activity
rwgk commentedon Mar 25, 2026
Standing issue, to document a known issue.
cpcloud commentedon Mar 25, 2026
I'm not following at all why an issue was opened and then immediately closed. Wouldn't #1817 close this issue?
build: replace inline docstring with reference to issue NVIDIA#1824
rwgk commentedon Mar 25, 2026
I wanted to leave the "Standing issue, to document a known issue." message.