Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
AI and LLM integration

TensorFlow on Linux or WSL2 skips the GPU and runs on the CPU

Your error

Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU.2 more lines it can show

Fix it fast

Most common cause, 1 of 4

Plain tensorflow was installed, without the and-cuda extra

Inside the activated venv, upgrade pip and reinstall with the extra.

Fix
python3 -m pip install --upgrade pip
python3 -m pip install 'tensorflow[and-cuda]'
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

TensorFlow prints Cannot dlopen some GPU libraries when it cannot load the CUDA and cuDNN files it was compiled against, then skips registering GPU devices. TensorFlow 2.21 needs CUDA 12.5 and cuDNN 9.3. Install tensorflow[and-cuda] so pip brings those libraries, link them if a system CUDA install gets in the way, and keep the NVIDIA driver current.

  • Applies to TensorFlow 2.21.0 (Python 3.10 to 3.13), CUDA 12.5 and cuDNN 9.3 (pip NVIDIA packages), Ubuntu 24.04 and WSL2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Run three checks in the same shell or venv as your code: does the driver see the card, did pip install the NVIDIA library packages, and which CUDA and cuDNN versions this TensorFlow build expects.

Run this first
nvidia-smi
python3 -m pip list | grep -i nvidia
python3 -c "import tensorflow as tf; b = tf.sysconfig.get_build_info(); print(tf.__version__, b.get('cuda_version'), b.get('cudnn_version'), tf.config.list_physical_devices('GPU'))"

Then find the line you see in this list and open its fix:

  1. 1Plain tensorflow was installed, without the and-cuda extrapip list shows no nvidia-* packages at all, and nothing like CUDA or cuDNN is installed system-wide
  2. 2The pip NVIDIA packages are present but are not found, or a system CUDA install winspip list shows nvidia-cudnn and nvidia-cuda packages, yet the GPU list is still empty
  3. 3System CUDA and cuDNN are from an older TensorFlow setupget_build_info prints CUDA 12.5 and cuDNN 9, while the machine only has CUDA 11.8 or cuDNN 8 libraries
  4. 4The NVIDIA driver is missing or too oldnvidia-smi fails, is not found, or reports a driver below 525.60.13 (Linux) or 528.33 (WSL2)

What does the error look like?

  • Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU.
  • Skipping registering GPU devices...
  • tf.config.list_physical_devices('GPU') returns []

Cause 1 of 4

Plain tensorflow was installed, without the and-cuda extra

You seepip list shows no nvidia-* packages at all, and nothing like CUDA or cuDNN is installed system-wide

Check

Cannot dlopen some GPU libraries appears when the TensorFlow wheel looks for CUDA runtime and cuDNN files that the machine does not have. The plain tensorflow package does not carry them; TensorFlow's pip guide uses tensorflow[and-cuda] for GPU users and plain tensorflow only for CPU users.

Check
python3 -m pip show tensorflow | grep -i -E '^(name|version)'

Fix

Inside the activated venv, upgrade pip and reinstall with the extra. Quote the name so the shell does not treat the brackets as a pattern.

Fix
python3 -m pip install --upgrade pip
python3 -m pip install 'tensorflow[and-cuda]'

Verify

pip list now shows the nvidia-* library packages, and the device check prints at least one PhysicalDevice of type GPU.

Verify
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Confirmed by tensorflow.org

Did this fix it?

Cause 2 of 4

The pip NVIDIA packages are present but are not found, or a system CUDA install wins

You seepip list shows nvidia-cudnn and nvidia-cuda packages, yet the GPU list is still empty

Check

TensorFlow's guide says that when the GPU test fails after a pip install, the usual reason is that the NVIDIA components are not being detected or clash with a CUDA install already on the system. Its answer to both is a set of symbolic links inside the venv.

Check
python3 -m pip show nvidia-cudnn-cu12 nvidia-cuda-runtime-cu12

Fix

Follow the guide's virtual-environment step: link the NVIDIA shared libraries next to the TensorFlow package, and link ptxas into the venv's bin folder.

Fix
pushd $(dirname $(python -c 'print(__import__("tensorflow").__file__)'))
ln -svf ../nvidia/*/lib/*.so* .
popd
ln -sf $(find $(dirname $(dirname $(python -c "import nvidia.cuda_nvcc; print(nvidia.cuda_nvcc.__file__)"))/*/bin/) -name ptxas -print -quit) $VIRTUAL_ENV/bin/ptxas

Verify

Run the GPU check again in the same venv. The dlopen warning is gone and the GPU is listed.

Verify
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Confirmed by tensorflow.org

Did this fix it?

Cause 3 of 4

System CUDA and cuDNN are from an older TensorFlow setup

You seeget_build_info prints CUDA 12.5 and cuDNN 9, while the machine only has CUDA 11.8 or cuDNN 8 libraries

Check

Each TensorFlow wheel is built against one CUDA and cuDNN pair. TensorFlow's tested build table lists 2.21.0 with CUDA 12.5 and cuDNN 9.3, while 2.13.0 used CUDA 11.8 and cuDNN 8.6. A machine prepared for 2.13 therefore has the wrong library versions for a current wheel.

Check
ldconfig -p | grep -E 'libcudnn|libcudart'

Fix

Let pip bring the versions this wheel wants: the and-cuda extra of 2.21.0 pulls nvidia-cudnn-cu12 9.3 or newer and the CUDA 12 runtime into the venv. If you must keep system libraries instead, install the CUDA and cuDNN pair the table gives for your TensorFlow release.

Fix
python3 -m pip install --upgrade 'tensorflow[and-cuda]'
python3 -m pip list | grep -i nvidia

Verify

The versions printed by get_build_info match the libraries in use, and a small matrix sum runs with a GPU listed.

Verify
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'), tf.reduce_sum(tf.random.normal([1000, 1000])))"

Confirmed by tensorflow.org

Did this fix it?

Cause 4 of 4

The NVIDIA driver is missing or too old

You seenvidia-smi fails, is not found, or reports a driver below 525.60.13 (Linux) or 528.33 (WSL2)

Check

Pip can deliver CUDA and cuDNN, but not the kernel driver. The pip guide asks for NVIDIA driver 525.60.13 or newer on Linux and 528.33 or newer for WSL on Windows, and starts GPU setup by checking nvidia-smi. Under WSL2 the driver is installed on the Windows side.

Check
nvidia-smi

Fix

Install or update the NVIDIA driver for your card (on Windows itself when you use WSL2), restart, and confirm nvidia-smi works before touching TensorFlow again.

Fix
nvidia-smi

Verify

nvidia-smi shows the card and a driver at or above the minimum, and TensorFlow lists the GPU.

Verify
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Confirmed by tensorflow.org

Did this fix it?

How do I stop it coming back?

  • Write tensorflow[and-cuda] with an exact version into requirements.txt so CI and new machines get the same CUDA libraries.
  • Install the GPU libraries only through the and-cuda extra in a fresh venv, instead of layering it over a system CUDA toolkit, which the pip guide names as a source of clashes.
  • Print the cuda_version and cudnn_version from tf.sysconfig.get_build_info() in the image build log, next to the output of nvidia-smi.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.