Skip to content

INFO: Import redirector requires a workaround in Jupyter notebooks #470

@leofang

Description

@leofang

Users usually install the needed dependencies like this

!pip install numba-cuda[cu12]

in the first cell of a notebook, and then use it in the next cell

from numba import cuda, ...

However, this does not work with the .pth redirector that we add to overwrite the upstream CUDA target:
https://github.com/NVIDIA/numba-cuda/tree/main/site-packages
because the .pth files must be executed at the startup time of the Python interpreter, and this execution logic implies that Python is already started by the Jupyter kernel.

Based on the offline discussion with @shwina we don't think there is a fix. Once the upstream Numba drops the CUDA target, we can drop this redirector. Before that happens, we can apply any of the workarounds below:

  1. Restart the kernel after !pip install
  2. Install the packages in terminal instead of cell, prior to starting a notebook
  3. import _numba_cuda_redirector before import numba or from numba import cuda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions