Why TensorFlow Is Not Detecting Your GPU (And How to Fix It)
In this article
TensorFlow not detecting your GPU almost always comes down to one of three things: the wrong TensorFlow build (CPU-only instead of GPU), a missing or mismatched CUDA/cuDNN installation, or a driver problem. The quickest check is to run python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))" — if it prints an empty list, TensorFlow cannot see your GPU. This guide walks through the fixes in order, from simplest to most involved.
What You'll Need
- A machine with a compatible NVIDIA GPU (TensorFlow's GPU support is built around NVIDIA CUDA; AMD and Apple GPUs need different setups).
- Python installed, ideally in a virtual environment so you can install and remove packages cleanly.
- Administrator access to install drivers and system libraries.
- The official NVIDIA driver for your GPU model.
- A note of which TensorFlow version you are using — CUDA and cuDNN versions must match it.
Step-by-Step
- Confirm TensorFlow can see the GPU at all. Open a terminal and run the check above. Also run
nvidia-smi(on Windows, in Command Prompt; on Linux, in a terminal). Ifnvidia-smifails or shows no GPU, the problem is the driver, not TensorFlow — reinstall the official NVIDIA driver first. - Check whether you installed the GPU build. Run
pip show tensorflow. The standardtensorflowpackage includes GPU support on recent versions, but older setups used a separatetensorflow-gpupackage. If you have both installed, uninstall both and reinstall one cleanly:pip uninstall tensorflow tensorflow-gputhenpip install tensorflow. Having two TensorFlow packages installed is a very common cause of silent GPU failure. - Verify the CUDA and cuDNN versions match your TensorFlow version. Each TensorFlow release is built against specific CUDA and cuDNN versions. Check the official TensorFlow install page for the version table, then compare with what is installed:
nvcc --versionshows the CUDA toolkit version. If they do not match, either install the matching CUDA/cuDNN or switch to a TensorFlow version that matches what you have. - Make sure the CUDA libraries are on the system path. On Windows, the CUDA bin directory (typically under
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vXX.X\bin) must be in the PATH environment variable. On Linux, add it toLD_LIBRARY_PATH. Missing DLL or.soerrors at import time usually mean this step was skipped. - Restart your terminal or IDE. Environment variable changes do not apply to already-open windows. Close and reopen your terminal, then rerun the check from step 1.
- Test inside a clean virtual environment. Create a fresh environment (
python -m venv tfenv, activate it), install TensorFlow there, and run the check again. This rules out conflicts with other packages in your main environment. - Check for conflicting GPU libraries. If you have PyTorch or other CUDA-dependent packages installed in the same environment, they may have pulled in a different CUDA runtime. Isolating TensorFlow in its own environment resolves this.
- Confirm the GPU is not disabled or reserved. On Windows, open Device Manager and check under Display adapters that the NVIDIA GPU is enabled and has no warning icon. On laptops with hybrid graphics, make sure the NVIDIA GPU is set as the preferred processor for your Python executable in the NVIDIA Control Panel.
Common Mistakes
- Installing
tensorflow-gpuon a modern TensorFlow version. That package is deprecated; the standard package handles GPU support now. Installing both creates conflicts. - Mismatching CUDA versions. Installing the newest CUDA toolkit rather than the one your TensorFlow version was built for is the single most common cause of an empty GPU list.
- Forgetting the PATH update. CUDA can be installed correctly and still be invisible to TensorFlow if its bin folder is not on the path.
- Testing in the wrong environment. Running the check in a different Python interpreter (for example, the system Python instead of your virtual environment) gives misleading results.
- Assuming any GPU works. TensorFlow's GPU support targets NVIDIA GPUs with CUDA compute capability. Integrated Intel graphics and most AMD GPUs are not supported through the standard path.
Tips
- Write down your TensorFlow version, CUDA version and cuDNN version before changing anything — it makes troubleshooting far faster.
- Use a virtual environment per project so a CUDA mismatch in one project does not break another.
- Run
nvidia-smifirst every time. If it works, the driver is fine and the issue is in the software stack. - Keep the NVIDIA driver reasonably current, but do not chase the newest driver if your CUDA version is pinned to an older one.
- Prefer the official TensorFlow installation instructions over random tutorials — version tables change and old guides go stale.
Troubleshooting
If the GPU list is still empty after the steps above, work through these in order:
- Import errors mentioning DLLs or shared libraries: the CUDA bin directory is not on the path, or the installed CUDA version does not match TensorFlow. Recheck step 3 and step 4.
- TensorFlow sees the GPU but training is slow: check that the operation is actually placed on the GPU. Simple operations may run on the CPU by design; confirm with
tf.config.list_physical_devices('GPU')and by checking for GPU memory usage innvidia-smiduring training. - Out-of-memory errors: another process may be holding GPU memory. Close other GPU-using apps, or configure TensorFlow's memory growth so it does not grab all memory at once.
- Works in one terminal but not another: environment variables differ between shells. Compare PATH and LD_LIBRARY_PATH between the two.
- Still stuck: uninstall TensorFlow and CUDA-related Python packages, reinstall the exact versions listed in the official TensorFlow install guide for your version, and test in a brand-new virtual environment before changing anything else.
Frequently Asked Questions
Why does TensorFlow show an empty GPU list even though nvidia-smi works?
Because the driver is fine but the software stack is not: usually a CUDA/cuDNN version mismatch, a missing PATH entry, or a CPU-only or conflicting TensorFlow installation.
Do I need to install CUDA separately?
Yes, for the standard TensorFlow GPU setup you install the NVIDIA driver, the CUDA toolkit and cuDNN versions that match your TensorFlow release. Some newer packaging options bundle the CUDA libraries, but the classic path requires them separately.
Can TensorFlow use an AMD or Apple GPU?
Not through the standard CUDA-based path. AMD and Apple GPUs require separate, platform-specific setups that are outside the normal TensorFlow GPU install.
Does reinstalling TensorFlow delete my models or data?
No. Uninstalling and reinstalling the Python package does not touch your saved models or datasets. Only the installed library files change.
Why did GPU detection stop working after an update?
An update may have changed the TensorFlow version, which changes the required CUDA and cuDNN versions. Recheck the version table and align your CUDA installation with the new TensorFlow version.
Is it safe to install multiple CUDA versions?
Yes, they can coexist, but only one should be on the PATH at a time. Point the PATH at the version that matches your TensorFlow installation.