python native_dependency_error ai_generated true

ImportError: libcuda.so.1: cannot open shared object file: No such file or directory

ID: python/importerror-libcuda

Also available as: JSON · Markdown
79%Fix Rate
83%Confidence
56Evidence
2019-03-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active

Root Cause

libcuda.so.1 is provided by the NVIDIA GPU driver (not the CUDA toolkit). This error means the driver is either not installed, not accessible (common in containers), or the library path is not configured. On systems with an NVIDIA GPU and driver installed, setting LD_LIBRARY_PATH or creating the proper symlink resolves the issue. In Docker, nvidia-container-toolkit must be configured.

generic

Workarounds

  1. 82% success Set LD_LIBRARY_PATH to include the NVIDIA driver library directory
    The driver library is typically at /usr/lib/x86_64-linux-gnu/ or /usr/local/cuda/lib64/ or /usr/lib64/. Run 'find / -name libcuda.so.1 2>/dev/null' to locate it, then 'export LD_LIBRARY_PATH=/path/to/dir:$LD_LIBRARY_PATH'. Add to .bashrc for persistence.

    Sources: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/#post-installation-actions

  2. 88% success Install the NVIDIA driver on the host system
    On Ubuntu/Debian: 'sudo apt update && sudo apt install nvidia-driver-535' (or latest version). On RHEL/CentOS: use the NVIDIA CUDA repository. Verify with 'nvidia-smi'. Reboot after installation.

    Sources: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/

  3. 85% success Configure NVIDIA Container Toolkit for Docker
    On the host: install nvidia-container-toolkit ('apt install nvidia-container-toolkit'), configure Docker runtime ('nvidia-ctk runtime configure --runtime=docker && systemctl restart docker'), then run containers with '--gpus all' flag: 'docker run --gpus all myimage'.

    Sources: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html

Dead Ends

Common approaches that don't work:

  1. Running 'pip install cuda' or 'pip install nvidia-cuda-runtime' 98% fail

    libcuda.so.1 is part of the NVIDIA GPU driver, not the CUDA toolkit or any pip-installable package. The GPU driver is a kernel module and userspace library installed at the OS level. No pip package can provide it because it must match the exact kernel module version loaded on the system.

  2. Running 'apt-get install nvidia-driver-xxx' inside a Docker container 92% fail

    GPU drivers cannot be installed inside containers. The driver runs at the host kernel level. Containers access the GPU through the NVIDIA Container Toolkit (nvidia-docker2 / nvidia-container-toolkit), which bind-mounts the host's driver libraries into the container at runtime.

  3. Installing cuda-toolkit without the driver component 75% fail

    The CUDA toolkit (installed via apt or runfile) includes development tools (nvcc) and libraries (cuBLAS, cuDNN) but does not always include the driver. When using the network repository, 'apt install cuda-toolkit-12-x' specifically excludes the driver. libcuda.so.1 is in the 'cuda-drivers' or 'nvidia-driver-xxx' package.

Error Chain

Leads to: