How to Install TensorFlow with Cuda and cuDNN support in Windows

Step 1 — Decide versions for CUDA,cuDNN, and Visual Studio

  • We will download the following versions.
  • CUDA 11.5
  • cuDNN 8.3
  • Microsoft Visual Studio 2019

Step 2 — Download CUDA Toolkit

Step 3 — Download cuDNN

  • If you have an account on Nvidia simply Login otherwise click on Join Now.
  • We will sleect the latest version (8.3) for CUDA 11.5 and we will download the zip for Windows.

Step 4 — Download Visual Studio 2019 Community.

  • Login to Microsoft and then search Visual Studio 2019 and download the Community version.
  • It will download a setup.
  • Install that setup.
  • It will ask to download workloads, just skip it and just install Visual Studio Core Editor.

Step 5 — Extracting and merging files

  • Once you have successfully downloaded CUDA and cuDNN, install the CUDA toolkit by double-clicking on it.
  • Agree and Continue > Express (Recommended). It can restart while installation process.
  • Then extract the cuDNN zip. It will produce 4 files.
  • Copy these 4 files and paste them into C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.5 and replace the files in destination.
  • Now open the bin Folder and copy the path from address bar.
  • Now open the start menu and type env and you will see an option “Edit the System Environment Variables”. A window like below will popup.
  • Click on Environment Variables here.
  • In the user variables (in the top section) double click on Path and click New.
  • Now paste the bin path you copied in a new field and hit OK.
  • Now do the same steps for libnvvp folder also.
  • Copy the path to libnvvp folder and add a new record in path.

Step 6 — Check successful installation of CUDA

  • Run the nvidia-smi command in your terminal.
  • You can see in the top right corner, CUDA Version: 11.5

Step 7 — Create conda environment and install TensorFlow

  • Now open your terminal and create a new conda environment.
  • Use the following command and hit “y”.
  • Here gpu is the name that I given to my conda environment.
conda create -n gpu python=3.9
  • Activate the conda environment and install TensorFlow (gpu version).
conda activate gpu
pip install tensorflow-gpu
  • Now simply copy the code below and paste it into a file named
import tensorflow as tftf.compat.v1.disable_eager_execution()with tf.device('/gpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
with tf.compat.v1.Session() as sess:
print (
  • Now run the python file in the conda environment.
  • If you see these results, bingo!! we have successfully installed TensorFlow with CUDA and cuDNN support :)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhishek Sharma

Abhishek Sharma

Data Scientist || Blogger || || Contact me for freelance projects on