Fix CUDA and cuDNN Library Load Errors in TensorFlow: A Diagnostic Guide
Quick answer
Almost every TensorFlow CUDA loading error has one of four causes: the library is genuinely missing, it is installed but not on the loader path (LD_LIBRARY_PATH), the CUDA/cuDNN version does not match what your TensorFlow build expects, or the library is optional and the message is only a warning. Run `ldconfig -p | grep <library>` first — if the library is listed, you have a path or version problem, not a missing package.
TensorFlow's GPU errors all look alike — some shared object could not be loaded — but they come from a small number of distinct causes. This guide gives you the order to check them in, then links to a detailed walkthrough for each specific error.
First: is it actually an error?
Not every red line is fatal. TensorFlow logs missing optional libraries at warning level and carries on:
Could not load dynamic library 'libnvinfer_plugin.so.6'
TensorRT is an optional inference optimiser. If your model still trains and tf.config.list_physical_devices('GPU') lists your GPU, nothing is broken. Confirm GPU availability before you change anything:
import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))If that returns a non-empty list, your GPU stack works and the message is noise. See the full explanation of the libnvinfer warning.
Second: is the library present, and can the loader see it?
This one command separates the two most commonly confused causes:
ldconfig -p | grep libcudart- Prints a path — the library exists. Your problem is a version mismatch or an environment that overrides the loader path.
- Prints nothing — search the filesystem before assuming it is missing:
find / -name 'libcudart.so*' 2>/dev/nullIf the file turns up but ldconfig did not list it, the directory simply is not on the loader path. Add it:
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATHAppend that line to ~/.bashrc to make it persistent. This is the fix for the classic libcublas.so.9.0 ImportError.
Third: does the version match your TensorFlow build?
The number in the filename is an ABI version and must match exactly. libcudart.so.11.0 is not satisfied by CUDA 12 — installing a newer CUDA does not fix it, and often causes it.
Check what you have against what TensorFlow wants:
nvcc --version # CUDA toolkit version
nvidia-smi # driver version and GPU memory
python -c "import tensorflow as tf; print(tf.__version__)"Then either install the CUDA version your TensorFlow build expects, or install a TensorFlow build compiled against your CUDA. Walkthrough: fixing the libcudart.so.11.0 error.
Fourth: is conda isolating or shadowing your CUDA?
Conda installs CUDA inside the environment prefix, not system-wide. Two failure modes follow: TensorFlow cannot find the environment's libraries, or a system CUDA install shadows them.
Keep everything in one environment and do not mix with a system install:
conda install -c conda-forge cudatoolkit cudnnDetails: TensorFlow not detecting CUDA installed through conda.
Runtime failures: CUDA_ERROR_LAUNCH_FAILED and CUDNN_STATUS_INTERNAL_ERROR
These appear after the libraries load, so they are not path problems. The usual cause is GPU memory exhaustion — TensorFlow grabs all GPU memory by default, leaving cuDNN unable to allocate its workspace. Enable memory growth first:
import tensorflow as tf
for gpu in tf.config.list_physical_devices('GPU'):
tf.config.experimental.set_memory_growth(gpu, True)If the failure persists, verify your cuDNN version matches your TensorFlow build. Full guide: troubleshooting CUDA_ERROR_LAUNCH_FAILED and CUDNN_STATUS_INTERNAL_ERROR.
The diagnostic checklist
Work top to bottom and stop at the first hit:
- Does
tf.config.list_physical_devices('GPU')list your GPU? If yes, treat load messages as warnings. - Does
ldconfig -p | grep <library>print a path? If no,findit; if found, add its directory toLD_LIBRARY_PATH. - Does the filename's version match what
nvcc --versionreports? If not, align TensorFlow and CUDA versions. - Are you in a conda environment? Install
cudatoolkitandcudnninside it and avoid mixing with system CUDA. - Do the libraries load but training crash? Enable GPU memory growth, then check cuDNN versions.
Most reported "broken CUDA installs" are step 2 or step 3 — a path or a version, not a missing package.
Key takeaways
- •Diagnose in this order: is it actually an error, is the file present, is it on the loader path, does the version match TensorFlow's build.
- •`Could not load dynamic library 'libnvinfer...'` is usually a harmless warning — TensorRT is optional and TensorFlow runs fine on GPU without it.
- •The number in the filename is the ABI version and must match exactly: libcudart.so.11.0 will not be satisfied by CUDA 12.
- •`ldconfig -p | grep libcudart` tells you instantly whether the loader can see a library — this single command separates 'missing' from 'not on path'.
- •Inside conda, install cudatoolkit and cudnn into the environment rather than relying on a system CUDA install, and never mix the two.
- •CUDNN_STATUS_INTERNAL_ERROR is usually GPU memory exhaustion or a version mismatch, not a corrupted install — enable memory growth before reinstalling anything.
Frequently asked questions
Why does TensorFlow say 'Could not load dynamic library libcudart.so.11.0'?
Your TensorFlow build was compiled against CUDA 11.0 and cannot find that exact runtime version. The trailing number is an ABI version that must match exactly, so a CUDA 12 install will not satisfy it. Either install the matching CUDA version or install a TensorFlow build compiled for the CUDA you have.
Is 'Could not load dynamic library libnvinfer_plugin.so.6' an actual problem?
Usually not. That library belongs to NVIDIA TensorRT, which is an optional inference optimiser. TensorFlow logs the message at warning level and continues to run normally on the GPU. You only need to act on it if you are deliberately using TensorRT integration.
How do I know whether a CUDA library is missing or just not on the path?
Run `ldconfig -p | grep libcudart` (substituting your library). If it prints a path, the library exists and the problem is your loader configuration or a version mismatch. If it prints nothing, run `find / -name 'libcudart.so*' 2>/dev/null` — if that finds the file, add its directory to LD_LIBRARY_PATH; if not, the package is genuinely missing.
Why doesn't TensorFlow detect CUDA installed through conda?
Conda installs CUDA inside the environment prefix rather than in a system directory, so the loader may not search it, and an active system CUDA install can shadow it. Install cudatoolkit and cudnn into the same conda environment as TensorFlow, activate the environment, and confirm with `python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"`.
What causes CUDNN_STATUS_INTERNAL_ERROR in TensorFlow?
Most often GPU memory exhaustion rather than a broken installation — TensorFlow allocates all GPU memory by default and cuDNN then fails to allocate its workspace. Enable memory growth with `tf.config.experimental.set_memory_growth`. If that does not help, check that your cuDNN version matches the version your TensorFlow build expects.
How do I permanently set LD_LIBRARY_PATH for CUDA?
Append the export to your shell profile (`~/.bashrc` or `~/.zshrc`), for example `export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH`, then run `source ~/.bashrc`. For a system-wide fix, add the directory to a file under `/etc/ld.so.conf.d/` and run `sudo ldconfig`.