TensorFlow
ImportError
libcusolver.so.8.0
shared object file
troubleshooting

Tensorflow ImportError libcusolver.so.8.0 cannot open shared object file No such file or directory

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The error ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory occurs when TensorFlow's GPU build cannot find the CUDA cuSOLVER library at the expected version. This typically means the installed CUDA toolkit version does not match what TensorFlow was compiled against, LD_LIBRARY_PATH does not include the CUDA library directory, or the CUDA installation is incomplete. The fix involves installing the correct CUDA version, setting environment variables, or creating symbolic links to match the expected library name.

Understanding the Error

 
>>> import tensorflow as tf
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory

TensorFlow GPU binaries are compiled against specific CUDA toolkit versions. Each TensorFlow release expects exact CUDA and cuDNN versions:

TensorFlowCUDAcuDNN
2.12-2.1511.88.6
2.10-2.1111.28.1
1.1510.07.4
1.129.07.1
1.5-1.89.07.0
1.0-1.48.06.0

If TensorFlow expects libcusolver.so.8.0 (CUDA 8.0) but CUDA 9.0 or 11.x is installed, the library name does not match and the import fails.

Fix 1: Install the Correct CUDA Version

bash
1# Check which CUDA version is installed
2nvcc --version
3# Or check the library directory
4ls /usr/local/cuda/lib64/libcusolver*
5
6# If you need CUDA 11.8 for TensorFlow 2.12+:
7# Download from NVIDIA: https://developer.nvidia.com/cuda-toolkit-archive
8wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
9sudo sh cuda_11.8.0_520.61.05_linux.run

The most reliable fix is installing the exact CUDA version that matches your TensorFlow build. Check the official TensorFlow build configurations for the correct version pair.

Fix 2: Set LD_LIBRARY_PATH

bash
1# Find where CUDA libraries are installed
2find / -name "libcusolver.so*" 2>/dev/null
3# Common locations:
4# /usr/local/cuda/lib64/
5# /usr/local/cuda-11.8/lib64/
6# /usr/lib/x86_64-linux-gnu/
7
8# Add to LD_LIBRARY_PATH
9export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
10
11# Make it persistent — add to ~/.bashrc
12echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
13source ~/.bashrc
14
15# Verify TensorFlow can now find it
16python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Even when the correct CUDA version is installed, TensorFlow may not find the libraries if LD_LIBRARY_PATH does not include the CUDA directory.

bash
1# If you have a newer version and need the older name
2# Example: you have libcusolver.so.11 but TF expects libcusolver.so.10
3ls /usr/local/cuda/lib64/libcusolver*
4# libcusolver.so.11.4.0.1
5
6# Create symlink (use with caution — version mismatch may cause runtime errors)
7sudo ln -s /usr/local/cuda/lib64/libcusolver.so.11 /usr/local/cuda/lib64/libcusolver.so.10
8
9# Rebuild the library cache
10sudo ldconfig

Symlinks are a temporary workaround. They can cause runtime crashes if the actual library API differs from what TensorFlow expects. Only use this for minor version differences (e.g., 11.4 vs 11.2), not major version gaps.

Fix 4: Use pip with the Correct TensorFlow Build

bash
1# Install TensorFlow that matches your CUDA version
2# For CUDA 11.8:
3pip install tensorflow==2.13.0
4
5# For CUDA 12.x (TensorFlow 2.16+):
6pip install tensorflow==2.16.0
7
8# Or use tensorflow-cpu to avoid CUDA entirely
9pip install tensorflow-cpu
10
11# Check TensorFlow's expected CUDA version
12python -c "import tensorflow as tf; print(tf.sysconfig.get_build_info())"

Instead of changing your CUDA installation, install the TensorFlow version built for your existing CUDA toolkit.

Fix 5: Use NVIDIA Docker Container

bash
1# Skip manual CUDA setup entirely — use the official TF GPU image
2docker run --gpus all -it tensorflow/tensorflow:latest-gpu bash
3
4# Inside the container, CUDA is pre-configured
5python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Docker containers with pre-configured CUDA eliminate version mismatch issues entirely. This is the recommended approach for reproducible GPU environments.

Fix 6: conda Installation

bash
1# conda manages CUDA dependencies automatically
2conda create -n tf-gpu python=3.10
3conda activate tf-gpu
4conda install tensorflow-gpu
5
6# conda installs the correct cudatoolkit and cudnn automatically
7conda list | grep cuda
8# cudatoolkit    11.8.0
9# cudnn          8.6.0

Conda resolves CUDA version dependencies automatically, installing the correct CUDA toolkit version alongside TensorFlow without affecting the system-wide CUDA installation.

Diagnosing the Issue

bash
1# Step 1: Check what TensorFlow expects
2python -c "import tensorflow as tf; print(tf.sysconfig.get_build_info())"
3
4# Step 2: Check what CUDA version is installed
5nvcc --version
6cat /usr/local/cuda/version.txt
7
8# Step 3: List available CUDA libraries
9ldconfig -p | grep cusolver
10
11# Step 4: Check GPU driver version (must support the CUDA version)
12nvidia-smi

Common Pitfalls

  • CUDA toolkit version mismatch: TensorFlow 2.12 requires CUDA 11.8 but you installed CUDA 12.0. Each TensorFlow release is compiled against a specific CUDA version — check the official compatibility table before installing.
  • Multiple CUDA installations conflicting: Having CUDA 10, 11, and 12 all installed on the same system can cause /usr/local/cuda to point to the wrong version. Use update-alternatives or explicit paths in LD_LIBRARY_PATH to select the correct one.
  • Symlink across major versions: Creating a symlink from libcusolver.so.11 to libcusolver.so.8 silences the import error but causes segfaults at runtime because the library ABI is incompatible. Only symlink within the same major version.
  • Forgetting ldconfig after installation: After installing CUDA or creating symlinks, run sudo ldconfig to refresh the shared library cache. Without this, the system linker may not find the new libraries.
  • GPU driver too old for CUDA version: CUDA 11.8 requires NVIDIA driver 520+. Run nvidia-smi to check your driver version. If the driver is too old, either upgrade the driver or install an older CUDA toolkit that matches your driver.

Summary

  • This error means TensorFlow cannot find the CUDA cuSOLVER library at the expected version
  • Install the exact CUDA toolkit version that matches your TensorFlow build (check the compatibility table)
  • Set LD_LIBRARY_PATH to include the CUDA library directory (/usr/local/cuda/lib64)
  • Use conda or Docker to automatically manage CUDA version dependencies
  • Avoid creating symlinks across major CUDA versions — they cause runtime crashes
  • Run ldconfig after any CUDA installation or library changes

Course illustration
Course illustration

All Rights Reserved.