Skip to content

Fix #299: Error message about bindings not working#300

Merged
kkraus14 merged 1 commit intoNVIDIA:mainfrom
gmarkall:fix-299
Jun 15, 2025
Merged

Fix #299: Error message about bindings not working#300
kkraus14 merged 1 commit intoNVIDIA:mainfrom
gmarkall:fix-299

Conversation

@gmarkall
Copy link
Contributor

To avoid a ModuleNotFoundError being raised when there is no cuda namespace package installed, we check for a spec for it first before checking for cuda.bindings.

To avoid a `ModuleNotFoundError` being raised when there is no `cuda`
namespace package installed, we check for a spec for it first before
checking for `cuda.bindings`.
@copy-pr-bot
Copy link

copy-pr-bot bot commented Jun 14, 2025

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@gmarkall
Copy link
Contributor Author

/ok to test

@gmarkall
Copy link
Contributor Author

A check on my machine when cuda and cuda.bindings do not exist:

$ python -m numba.runtests numba.cuda.tests
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/site-packages/numba/runtests.py", line 9, in <module>
    sys.exit(0 if _main(sys.argv) else 1)
                  ^^^^^^^^^^^^^^^
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/site-packages/numba/testing/_runtests.py", line 25, in _main
    return run_tests(argv, defaultTest='numba.tests',
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/site-packages/numba/testing/__init__.py", line 54, in run_tests
    prog = NumbaTestProgram(argv=argv,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/site-packages/numba/testing/main.py", line 204, in __init__
    super(NumbaTestProgram, self).__init__(*args, **kwargs)
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/unittest/main.py", line 105, in __init__
    self.runTests()
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/site-packages/numba/testing/main.py", line 376, in runTests
    run_tests_real()
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/site-packages/numba/testing/main.py", line 361, in run_tests_real
    super(NumbaTestProgram, self).runTests()
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/unittest/main.py", line 281, in runTests
    self.result = testRunner.run(self.test)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/site-packages/numba/testing/main.py", line 167, in run
    run.sort(key=cuda_sensitive_mtime)
  File "/home/gmarkall/miniforge3/envs/test-numba-cuda-0151-wheel/lib/python3.12/site-packages/numba/testing/main.py", line 82, in cuda_sensitive_mtime
    from numba.cuda.testing import CUDATestCase
  File "/home/gmarkall/numbadev/numba-cuda/numba_cuda/numba/cuda/__init__.py", line 37, in <module>
    raise ImportError(
ImportError: CUDA bindings not found. Please pip install the cuda-bindings package. Alternatively, install numba-cuda[cuXY], where XY is the required CUDA version, to install the binding automatically. If no CUDA bindings are desired, set the env var NUMBA_CUDA_USE_NVIDIA_BINDING=0 to enable ctypes bindings.

@gmarkall
Copy link
Contributor Author

I do wonder if there could be other sources of exceptions that we might not catch, from the info in https://docs.python.org/3/library/importlib.html#importlib.util.find_spec - for example, if cuda is a module in the environment (and not a package) perhaps ModuleNotFoundError could get raised by find_spec("cuda"). This might be more of a corner case / less likely to arise though.

@kkraus14 kkraus14 merged commit 510d7f1 into NVIDIA:main Jun 15, 2025
39 checks passed
gmarkall added a commit to gmarkall/numba-cuda that referenced this pull request Jun 24, 2025
- Clarify pynvjitlink option precedence. (NVIDIA#303)
- update readme and point to the doc (NVIDIA#301)
- Fix NVIDIA#299: Error message about bindings not working (NVIDIA#300)
@gmarkall gmarkall mentioned this pull request Jun 24, 2025
gmarkall added a commit that referenced this pull request Jun 24, 2025
- Clarify pynvjitlink option precedence. (#303)
- update readme and point to the doc (#301)
- Fix #299: Error message about bindings not working (#300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments