InterviewsVector

TensorFlow Not Detecting GPU / CUDA Installed via Conda: The Version-Match Fix

Quick answer

TensorFlow ships built against specific CUDA and cuDNN versions, so tf.config.list_physical_devices('GPU') returns [] when the installed versions don't match, or when a system CUDA install shadows the conda one. The modern fix on Linux is pip install tensorflow[and-cuda], which bundles matching CUDA/cuDNN wheels. Otherwise install the exact cudatoolkit and cudnn versions TensorFlow expects into the same conda env and don't mix conda with a system CUDA. The tensorflow-gpu package is deprecated.

Short answer: TensorFlow is built against specific CUDA/cuDNN versions, so tf.config.list_physical_devices('GPU') returns [] when the installed versions don't match — or when a system CUDA install shadows the conda one. On Linux, the modern fix is pip install tensorflow[and-cuda] (bundles matching CUDA/cuDNN). Otherwise, install the exact cudatoolkit/cudnn TensorFlow expects into the same conda env. tensorflow-gpu is deprecated.

You installed CUDA through conda, nvidia-smi shows the GPU, but TensorFlow still runs on CPU. This is almost never "CUDA isn't installed" — it's a version mismatch or a conda-vs-system conflict.

Step 1 — confirm what TensorFlow actually sees

import tensorflow as tf
print(tf.config.list_physical_devices("GPU"))   # []  -> not detected
# What CUDA/cuDNN this TF build expects:
info = tf.sysconfig.get_build_info()
print(info["cuda_version"], info["cudnn_version"])

Compare that against the driver and toolkit actually present:

nvidia-smi          # driver + max CUDA the driver supports
nvcc --version      # toolkit version on PATH (may differ from conda's)

If cuda_version from TensorFlow doesn't match what's installed, that's your bug. TensorFlow built against CUDA 11.8 will not use a CUDA 12 install.

The root cause

Conda installs CUDA inside the environment prefix ($CONDA_PREFIX), not a system directory. TensorFlow may not look there, or a system CUDA install may be found first and shadow the conda one. Mixing the two is the classic trap.

The simplest reliable path is to stop matching versions by hand and let the wheel do it:

pip install 'tensorflow[and-cuda]'

This pulls the exact CUDA/cuDNN pip wheels TensorFlow was built against, into the environment — no manual cudatoolkit/cudnn install needed.

Fix 2 — matched conda environment

If you prefer conda, install the exact versions TensorFlow expects into the same env (check TensorFlow's tested-build compatibility table):

conda create -n tf python=3.11
conda activate tf
conda install -c conda-forge cudatoolkit=11.8 cudnn=8.6   # match your TF build
pip install tensorflow

Then make sure the env's libraries are on the path:

export LD_LIBRARY_PATH="$CONDA_PREFIX/lib:$LD_LIBRARY_PATH"

Common pitfalls

  • Mixing conda and system CUDA — pick one; a system install often wins on LD_LIBRARY_PATH.
  • Installing a CPU-only buildpip install tensorflow on macOS, or a mismatched wheel, yields no GPU.
  • Using tensorflow-gpu — deprecated; use tensorflow / tensorflow[and-cuda].
  • Native Windows — TensorFlow dropped native-Windows GPU support after 2.10; use WSL2 with tensorflow[and-cuda].

Sources

Key takeaways

  • Confirm the problem with tf.config.list_physical_devices('GPU') — an empty list means no GPU detected.
  • The usual cause is a CUDA/cuDNN version mismatch: TF is built against exact versions (CUDA 11.8 build won't use CUDA 12).
  • Modern fix on Linux: pip install tensorflow[and-cuda] bundles the matching CUDA/cuDNN wheels — no manual install.
  • For conda, install the exact cudatoolkit + cudnn TF expects into the same env; don't mix conda and system CUDA.
  • tensorflow-gpu is deprecated (merged into tensorflow); native Windows GPU support ended at TF 2.10 — use WSL2.

Frequently asked questions

How do I check if TensorFlow sees my GPU?

Run import tensorflow as tf; print(tf.config.list_physical_devices('GPU')). A non-empty list means the GPU is detected. If it's empty, TensorFlow is not finding a compatible CUDA/cuDNN, or you installed a CPU-only build.

Why doesn't TensorFlow use the CUDA I installed with conda?

TensorFlow is compiled against specific CUDA and cuDNN versions. If the conda-installed versions don't match, or a system CUDA install is found first, TensorFlow silently falls back to CPU. Match the versions to what your TensorFlow build expects, or install tensorflow[and-cuda] which bundles them.

What is the difference between tensorflow and tensorflow-gpu?

There is no longer a difference — tensorflow-gpu is deprecated. Since TensorFlow 2.x, the standard tensorflow package includes GPU support. On Linux, pip install tensorflow[and-cuda] additionally pulls the matching CUDA/cuDNN libraries.

By Mohammad Wasi

Software Engineering Leader & Technical Author · Updated August 26, 2026


Related Posts