It’s been just 2 days since Windows 11 came out and I am already setting up my system for the ultimate machine learning environment. Today we are going to setup a new anaconda environment with tensorflow 2.5 with GPU support using NVIDIA CUDA 11.4 and CUDNN 8.2.4 along with Python 3.8. This is going to be a handson practical step by step guide to create this environment from scratch with a fresh Windows 11 installation.

I have a decent machine with a decent GPU and I do some hobby machine learning projects. I know getting the CUDA support up and running on tensorflow is such a pain point and that is why we have all these posts and videos on different platforms how to do it properly. This blog post is yet another such post but the idea here is – I am writing this as I am setting up the things and this blog post should help you setup your environment just like I did.
I would argue that recently it has become very simple and straightforward to get up and running on Windows (Windows 11 specifically). Before we get started here are the set of software that you need to install on your machine. Some of this software is optional but I like to have a fully loaded environment so that I don’t have to wait for the software/tools installation later on when I have some awesome idea.
My Environment
My environment is as follows.
- Operating System: Windows 11 Pro (everything in artical would work on Windows 11 editions)
- Processor: AMD Ryzen Threadripper 2970WX (CPU doesn’t matter)
- Motherboard: Asus Rog X399 (Any motherboard is fine)
- Graphics Card: NVIDIA GeForce RTX 2070 8GB GDRR6 (any RTX or Quadro GPU is fine)
I have added a new way of running tensorflow with GPU using docker containers, that approach is much simpler and more robust then configuring the entire drivers and CUDA libraries on your local machine. Checkout the article at the below link.
https://thegeeksdiary.com/2023/01/29/how-to-setup-tensorflow-with-gpu-support-using-docker/

Steps
You will need the following installed on your machine.
- NVIDIA Graphics Driver: I am using driver version 510.06 gameready drivers. These drivers are special because they also include WSL 2 support which means that I would be able to use the same drivers inside my WSL2 distributions – if you don’t understand WSl 2 – that is fine – you don’t need to. You can download the current version of the drivers from this link.
- Visual Studio 2019 – for C++ runtime: You can down it from the official website here. Please note that Visual Studio 2019 community edition is free to download and install. I will explain the installation process below.
- Miniconda: You can get the latest version on Miniconda from here. As of this writing I am using Miniconda 3 64 bit version. The version of python included with base environment is 3.9.
- CUDA Toolkit for Windows 11: In order for us to be able to use CUDA capable software and libraries we would need the CUDA SDK or CUDA Toolkit as it is often known. This provides us the set of primitives and libraries that interact with the underlying hardware. CUDA Toolkit also includes NVCC compiler which is a specialized C/C++ compiler that compiles code which is able to run CUDA capable GPUs. You can download the CUDA toolkit form this link. As of this writing the current version of CUDA toolkit is 11.4.
- CUDNN: CUDNN is a set of C/C++ Libraries that expose the deep neural network capabilities on top CUDA. All deep learning frameworks use CUDNN to use NVIDIA GPUs – including tensorflow.
- Create a Conda environment: After installing all the software we will just create a new conda environment.
Step 1: NVIDIA Graphics Driver Installation
I am starting off with a fresh install of Windows 11 so I need to make sure that I have applied all the latest updates. Although not necessary it is good to install them so that any dependencies needed by the software that we will install later is installed smoothly. Once done, you can visit this page to get the latest NVIDIA GPU Driver (note that this is a special driver that adds WSL2 GPU sharing capabilities – you can event install the normal driver for the steps mentioned in this article). Even a simple google search will lead you to this page https://www.nvidia.com/Download/index.aspx. On this page you need to select your graphics card and operating system to be able to download the correct driver. Here is an example selection for my setup.

Once you have downloaded the setup binary – just double click on the file to run it. Just click next as many times you are prompted to :-). Congratulations you have just completed step 1.

Step 2: Visual Studio 2019
As of this writing the stable version of Visual Studio that is available is Visual Studio 2019. I am using the community edition which is a full development environment. If you have any other license (professional or enterprise) that is also fine. Download the visual studio installer from https://visualstudio.microsoft.com/downloads/. Double click the file and make sure that you have the highlighted (“Desktop development with C++”) workloads installed. This will install the required C++ toolchain.

This will take a while to install depending on the workloads that you have selected. wait for it to finish. You might have to restart your computer before going on to next step.

Step 3: Miniconda
Anaconda is a python distribution that allows you to have several python environments on one machine. This gives you the freedom to work with multiple isolated versions of python without relying on a global environment which might have package conflicts. Isolation is always good. Head over to https://docs.conda.io/en/latest/miniconda.html to download a trimmed version of Anaconda otherwise known as Miniconda. Download the installer and finish the steps with the regular options.


Step 4: CUDA Toolkit for Windows 11
You can download and install the CUDA toolkit by visiting this link https://developer.nvidia.com/cuda-downloads. As of this writing I am using CUDA Toolkit version 11.4. Download the installer and just click next until finished – it’s simple.

Step 5: CUDNN Library
Now it’s time for us to install the CUDNN library for which is used by tensorflow for creating deep neural networks on GPU using CUDA. Visit the page https://developer.nvidia.com/rdp/cudnn-download and download CUDNN for CUDA Version 11.4 (as of this writing latest version 11.4 for CUDA and 8.2.4 for CUDNN). Please note that you need have a NVIDIA developer account with NVIDIA which is free to create – I guess everybody want have your email address today.

Download the zip file as shown above, extract the contents in any directory. Open the extracted folder, and also open another explorer window with the following path: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA. Inside this folder you will find a folder for your current CUDA toolkit version, for example for me it is v11.4. Copy the files from the extracted folder like so. In the below tables ALL_CAPS values like these refer to the specific parameters specific to your environment for example CUDA_VERSION refers to the version of CUDA that you downloaded, likewise EXTRACTED_FOLDER refers to the path where you extracted the CUDNN Library zip file.
Source | Destination |
<EXTRACTED_FOLDER>\bin\* | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v<CUDA_VERSION>\bin\ |
<EXTRACTED_FOLDER>\include\* | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v<CUDA_VERSION>\include\ |
<EXTRACTED_FOLDER>\lib\x64\* | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v<CUDA_VERSION>\lib\x64 |
Please note that you need to copy the files of the above folders and not the folders themselves. After this verify that you have the below listed Environment Variables created on you machine.
Environment Variable | value |
CUDA_PATH | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v<CUDA_VERSION> |
CUDA_PATH_V<CUDA_VERSION> | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v<CUDA_VERSION> |
If you need to know how to access and set environment variables on Windows 11, refer to this article. Although these instructions are for Windows 10 but they still apply to Windows 11.

Step 6: Create a Conda environment
This is now the moment of truth. In this step we will created the Conda environment with Python version 3.8. Let’s start.
Open the Anaconda Prompt by going to start menu.


Once on the prompt run the following commands.
# install Jupyter Notebook in our base environment
conda install -y jupyter
# create a new environment with name 'tensorflow-gpu' and python version 3.8
conda create --name tensorflow-gpu python=3.8
# activate the environment
conda activate tensorflow-gpu
# install python 2.5
pip install tensorflow==2.5
# enable notebook support in our environment
conda install -y -c conda-forge nb_conda
# add the environment to Jupyter Kernel
python -m ipykernel install --user --name tensorflow-gpu --display-name "Python 3.8 (tensorflow-gpu)"
# deactivate the environment
conda deactivate
# create a new directory for our test notebook to check the tensorflow GPU initialization
mkdir test-installation
# go inside the new directory
cd test-installation
# activate our test environment
conda activate tensorflow-gpu
# start jupyter notebook
jupyter notebook
This will open a browser window as shown below.


Now create a new notebook by clicking on the “New” toolbar on the right hand corner as shown below, make sure that you select the kernel name as “Python 3.8 (tensorflow-gpu)” – my environment name is “Teflon-GPU-TF (Python 3.8)” but if you followed the above commands yours environment name will be Python 3.8 (tensorflow-gpu). This will open a new blank notebook as shown below.

Yours notebook will be empty (whereas above has code – which you need to paste from below).
import sys
import tensorflow.keras
import tensorflow as tf
import numpy as np
print(f"Tensor Flow Version: {tf.__version__}")
print(f"Keras Version: {tensorflow.keras.__version__}")
print()
print(f"Python {sys.version}")
gpu = len(tf.config.list_physical_devices('GPU'))>0
print("GPU is", "available" if gpu else "NOT AVAILABLE")
After running the above code in the notebook you should see an output similar to the one shown below.

Tensor Flow Version: 2.5.0
Keras Version: 2.5.0
Python 3.8.11 (default, Aug 6 2021, 09:57:55) [MSC v.1916 64 bit (AMD64)]
GPU is available
Congratulations you have just completed your environment setup with Miniconda. You can now build great deep learning models using your GPU. Please comment below if you face any issues.
I have added a new way of running tensorflow with GPU using docker containers, that approach is much simpler and more robust then configuring the entire drivers and CUDA libraries on your local machine. Checkout the article at the below link.
https://thegeeksdiary.com/2023/01/29/how-to-setup-tensorflow-with-gpu-support-using-docker/
I have created a series on tensorflow deep learning – checkout the first article in that series here.
https://thegeeksdiary.com/2023/03/23/introduction-to-deep-learning-with-tensorflow-deep-learning-1/
Leave a Reply