Install TensorFlow GPU on Windows – A complete guide 2023

TensorFlow is an end-to-end open source platform for machine learning from Google. If you want to study Ai or work on Ai project, setting up an development env with TensorFlow at a local machine will help you have smooth sailing. GPU (Graphics processing unit) is a specialized processor originally designed to process data simultaneously. It helps to speed up computation of your deep learning code. This is a complete guide to install TensorFlow GPU on windows in 2023. The installation involves many steps. Let’s get started.

Table of Content

  1. Download Nvidia graphics driver
  2. Check software compatibilities at Tensorflow site
  3. Install Visual Studio Community 2019
  4. Install CUDA Toolkit 11.8.0
  5. Install cuDNN 8.6
  6. Install Anaconda3
  7. Create virtual environment
  8. Install Tensorflow 2.10
  9. Install PyCharm
  10. Install additional packages

1. Download Nvidia graphics driver

If you already have a PC with GPU, you can skip this step. If you are going to get a new machine learning PC with GPU, please check CUDA enabled GPU cards before buying one. I suggest you buy a PC with Nvidia graphic card having at least 12GB GDDR6 or GDDR6X. If you just got a new PC with Nvidia GPU, you go to Nvidia driver download and download the graphic card driver. After download, you run exe file to install.

Nvidia driver downloads

2. Check software compatibilities at Tensorflow site

Normally you get the latest version when install a software. That’s not the case here. You have to check the compatibilities between software. Go to TensorFlow install guide to get software requirements. This will help you avoid headaches.

Tensorflow software requirements

3. Install Visual Studio Community 2019

TensorFlow install guide says “Windows Native Requires Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019.” Please note it is not latest version 2022. You go to Visual Studio old downloads to get 2019. After you sign in, select community 2019 and download.

download vs 2019

When you run installer, select “code editor” at the right side of the window. Click “continue” and finish the installation.

4. Install CUDA Toolkit 11.8.0

CUDA is a software layer that gives direct access to the Nvidia GPU’s virtual instruction set and parallel computational elements. According to Tensorflow install guide, you need CUDA 11.8. Go to CUDA Toolkit archive at Nivdia, and select CUDA ToolKet 11.8.0. In the next window, select Windows, version of your operation system and installer type, you can download and follow default to install it.

download cuda toolkit

It is installed at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\.

5. Install cuDNN 8.6

The Nvidia CUDA® Deep Neural Network library (cuDNN) is a GPU-accelerated library of primitives for deep neural networks. Go to Nvidia’s cuDNN Archive, download cuDNN v8.6 (not the latest).

download cuda toolkit

Extract the downloaded zip file and copy three sub folders, i.e. include, lib and bin.

cuDNN lib

Paste them to CUDA install folder at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\. New files are added to CUDA.

cuda folder

Open Environment Variables window, add following new two paths:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\libnvvp

environment variables

6. Install Anaconda3

Conda is an open-source package and environment management system that runs on Windows, macOS, and Linux. Conda quickly installs, runs, and updates packages and their dependencies. To install, go to Anaconda site to download Anaconda installer, click the download button at top or go to bottom to select particular version for your PC.

download anaconda

After you run the installer, Anaconda3 is installed at C:\Users\yourusername\anaconda3. It also installs Python 3.10 there. Remember to add the following paths in “Environment Variables”:

environment variables

In window start, you can find Anaconda3 folder. If you cannot find, search for “Anaconda prompt” in window search bar at the bottom. Create a shortcut of Anaconda prompt on your desktop. You will use it a lot.

Anaconda start folder

Run Anaconda prompt, a prompt window opens. It shows (base) C:\Users\yourusername>. (base) represents your current environment. “base” is a default env.

anaconda prompt

You can run conda or pip commands to see what packages have been installed.
$conda list
$pip list

7. Create virtual environment

A virtual environments is an isolated environment for Python projects. Each project can have its own dependencies, regardless of what dependencies every other project has. Now we create a virtual environment for TensorFlow GPU support. Open Anaconda prompt window, enter commands:
$conda create –name tf_env python=3.10
$conda activate tf_env

virtual env

(tf_env) at the beginning of the prompt shows you are in “tf_env” env.

8. Install Tensorflow 2.10

TensorFlow requires a recent version of pip, so upgrade your pip installation to be sure you’re running the latest version. Enter the following command in Anaconda prompt.
$pip install –upgrade pip

Please check out TensorFlow install guide for windows. You should install TensorFlow 2.10.

tensorflow windows native

To install TensorFlow 2.10, enter the following command in Anaconda prompt.
$pip install “tensorflow<2.11"
This command installs TensorFlow for both CPU and GPU, and other common used packages such as keras, numPy.

To check whether TensorFlow installed correctly with GPU support, enter the following command in Anaconda prompt:
$python -c “import tensorflow as tf; print(tf.config.list_physical_devices(‘GPU’))”
If it returns something like following line, you have successfully installed TensorFlow with GPU support.
[PhysicalDevice(name=’/physical_device:GPU:0′, device_type=’GPU’)]

test TensorFlow GPU

9. Install PyCharm

Now you can use Jupyter Notebook in Anaconda3 to enter and run your project. But I prefer to use IDE, which gives me more control. PyCharm is an integrated development environment used for programming in Python. Go to Download PyCharm at jebrains site. Download the Community version and run the installer.

After installation, open PyCharm and create a new project. In Python interpreter, check “Previously configured interpreter”. In the drop down, select “tf_env” you just created.

pycharm new project

If you have created a project before and want to change virtual environment, you can go to file->settings -> project. In Python interpreter, check using existing environment. In drop down, you can select other env.

10. Install additional packages

To install additional packages or modules, you can run pip in Anaconda prompt. For example,
$pip install scikit-learn
$pip install pandas
The latest version will be installed.

For some package, you may need to install a particular version. Here is an example,
$pip install protobuf==3.19.*

You may want to use Transformers module in your project as well. I suggest you create another virtual environment “transformer_env”. Install TensorFlow first as described above, then run command:
$pip install transformers

Comments are closed