Error database

Could not load dynamic library 'libcudart.so' (TensorFlow)

TensorFlow cannot find the CUDA libraries it wants, so it silently falls back to CPU. On Linux, install with pip install tensorflow[and-cuda]; on Windows, use WSL2 for GPU support.

The message you saw
Could not load dynamic library 'libcudart.so' (TensorFlow)

By Updated

The error

Output
Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory

Usually in a cluster of similar lines — libcublas, libcudnn, libcufft — followed by:

Output
Skipping registering GPU devices...

What it means

TensorFlow looked for NVIDIA's CUDA libraries on the system and did not find the versions it was built against. These are warnings, not crashes: TensorFlow continues on CPU. That is the trap — training runs, at a tenth of the speed, and nothing shouts about it. The exact .so version in the message tells you which CUDA generation your TensorFlow expects.

Why it happens

Unlike PyTorch wheels, classic TensorFlow installs did not bundle CUDA — they expected a system-wide CUDA toolkit and cuDNN of exactly the right version. Almost nobody's system matches by accident. Modern TensorFlow fixed this with an install extra that brings the CUDA libraries along, but plain pip install tensorflow still leaves GPU support to luck on many setups. On Windows, there is a harder wall: native Windows GPU builds ended with TensorFlow 2.10.

How to fix it

1. On Linux (or WSL2), install with the CUDA extra.

bash
pip install "tensorflow[and-cuda]"

This pulls matching NVIDIA libraries as pip packages — no system CUDA toolkit needed. Only the driver must be present (nvidia-smi should work). Then verify:

python
import tensorflow as tf
print(tf.config.list_physical_devices("GPU"))
Output
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

An empty list means it is still on CPU — read the log lines above it for which library is missing.

2. On Windows, use WSL2 for GPU TensorFlow. Install the normal Windows NVIDIA driver, then inside a WSL2 Ubuntu run the same tensorflow[and-cuda] install. Native Windows TensorFlow 2.11+ is CPU-only; the old workaround of pinning 2.10 locks you out of years of fixes.

3. In conda environments, take the packaged pair.

bash
conda install -c conda-forge cudatoolkit cudnn

Useful on clusters where pip-provided NVIDIA packages clash with site policy. Match versions to what your TensorFlow build expects — the missing .so numbers in the log are the requirement list.

4. Decide whether you need GPU at all. For learning-sized models, CPU TensorFlow is fine, and the warnings are ignorable. The danger is only thinking you are on GPU when you are not — the verify snippet settles it.

How to prevent it

Make the list_physical_devices("GPU") check part of every training script's startup, and log it. Prefer tensorflow[and-cuda] over hand-maintained system CUDA installs — version drift between toolkit, cuDNN and framework is precisely what it eliminates.