Installing TensorFlow With GPU on Windows 10

DZone 's Guide to

Installing TensorFlow With GPU on Windows 10

Learn how to test a Windows system for a supported GPU, install and configure the required drivers, and get a TensorFlow nightly build and ensuring that it works.

· AI Zone ·
Free Resource

In an earlier article, I showed how to test your Linux system to see if you have a GPU that supports TensorFlow, with the promise that I'd next do Windows and MacOS. So, in this article, I will show how you can test a Windows system for a supported GPU, and if you have one, how you can then install and configure the required drivers before getting a TensorFlow nightly build and ensuring that it works.

But before you go any further, you'll also need Python and pip, which don't typically come with Windows machines.

Getting Python and pip

There are quite a few ways to install Python and pip for Windows, but I found the easiest to be to go to the Python site and download the executable installer.

Once you've downloaded it, launch it and be sure to select the custom option for install. This takes you into a configuration dialog where you can select pip as an option to install.

I'd recommend you just choose them all.

Once you've finished installing, you can open a command prompt and type python to see which version you're using. As you can see from the above I downloaded 3.6.4, and my Python command matches this.

You can exit the Python interpreter with


And then test your pip install with:

pip -V

You should see something like this:

You're now good to go with the Python runtime and pip installer for Windows. You'll use these to install TensorFlow, but first, let's check on your GPU to see if it is supported.

Checking Your Windows GPU

From your command prompt, you can launch Device Manager with this command:

control /name Microsoft.DeviceManager

Then look for the Display adapter setting, open it, and read the name of your adapter. You should see something like this:

As you can see, my system has a GTX 980 Ti. Take note of yours, and visit NVidia's site of GPUs that support CUDA here. If your card is on the list (my GTX 980 Ti is), then you know that TensorFlow can support GPU operations on your machine — but before you can install and run TensorFlow, you'll need to install the CUDA drivers for your machine and the CUDNN updates for it.

Installing the CUDA Drivers

At the time of writing, the TensorFlow nightly builds support CUDA 9.0, and the release builds support 8.0. If you visit the CUDA downloads site here, you'll notice that it will take you to the latest version (right now it's 9.1), so be sure to download the right version of the driver by selecting the Legacy Resources link at the bottom of the downloads screen:

Of course, as CUDA and TensorFlow get updated, these versions will change. If you have the incorrect version, TensorFlow will warn you (I'll show you where later in this article) and you'll have to go back to this site to get the correct version. Download the drivers for your system and install them using defaults. It takes a little while, and a couple of reboots, so while you're waiting, check out a couple of episodes of Coffee With a Googler!

You'll also need a version of CuDNN that matches your version of CUDA before you can run TensorFlow, but I've found it easier not to install it yet — you want to ensure that you have the right CUDA first, so, while it might seem counterintuitive, you should install TensorFlow first and try to get it to run. One of two things will happen:

  1. It will fail on the CUDA drivers, so you'll need to repeat this step.
  2. It will fail on the CuDNN drivers, so you know your CUDA drivers are good and you will get the version of CuDNN that you need.

So, let's install TensorFlow next.

Installing TensorFlow Nightly Build

I'm assuming here you're using TensorFlow with GPU, so to install it from a command prompt, simply type:

sudo pip install tf-nightly-gpu

(Replace with tf-nightly if you don't want the GPU version.)

Then, once it's completed, in your command prompt window, type:


...to open the Python editor, and within it, type:

import tensorflow as tf

If you are using the GPU version, you should get an error. That's good.

If you have the wrong CUDA drivers, it will likely show that cudart64_XX.dll fails, where XX is a version number. At the time of writing, it is cudart_90.dll, which tells you that you need version 9.0 of the CUDA drivers. Check this version carefully, and repeat the previous step (downloading and installing the drivers) until this error goes away. Be sure to close the command prompt window, and open a new one to test the new installation so your paths are up to date.

When you have the right CUDA drivers, but the wrong or missing CuDNN drivers, you'll see an error saying something like cudnn64_X.dll is missing, where X is a version number. Take note of that — you'll use it in the next step. Exit Python and close the command prompt window before continuing. In my case, it told me that cudnn64_7.dll was missing, so I know I need version 7.

Installing the CuDNN Libraries

The CuDNN libraries are an update to CUDA for deep neural nets and are used by TensorFlow to accelerate deep learning on NVidia GPUs. You can download them from here. You'll have to sign up for an NVidia developer account first, but it's pretty quick and costs nothing. Once you've signed in, you'll see a variety of CuDNN downloads. Here's where you'll have to match to the version of CUDA that you downloaded in the previous section. So, for example, I used CUDA 9.0, so I made sure I used a CuDNN that matches both this and the required version you saw in the last step (in my case version 7) — I chose cuDNN v7.0.5 for CUDA 9.0.

This will download a ZIP file with several folders, each containing the CuDNN files (one DLL, one header, and one library). Find your CUDA installation... should be at something like:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0

You'll see the directories from the ZIP file are also in this directory, i.e. there's a bin, an include, a lib, etc. Copy the files from the ZIP to the relevant directory. So, for example, drag cudnn64_7.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin, and do the same for the others. You can see more here.

Once you're done, re-open a command prompt window and test TensorFlow again!

Testing TensorFlow

If all goes to plan, you can now open a command prompt window, and type 'python' to open the Python interpreter. Then type:

import tensorflow as tf

And if you have the right versions of the libraries, you should see no error, like this:

If you see errors in cudart64_xx.dll or cudnn64_x.dll, go back to the previous steps and make sure you've downloaded and installed the correct versions of the drivers that cause these errors. It takes a bit of trial and error, I'm afraid.

Then, you can check your TensorFlow version by typing:


Note that there are two underscores before and after version. TensorFlow will output its version number, as shown here:

You now have a full TensorFlow runtime environment with GPU support on Windows! Congratulations. Time to do some deep learning...

ai ,gpu ,python ,tensorflow ,tutorial ,deep learning

Published at DZone with permission of Laurence Moroney , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}