Setting up TensorFlow (GPU) on Windows 10 | by Peter Jang | Towards Data Science

Personally, I despise spending hours setting up machine learning tools for training — especially on Windows.
After many trials and errors for the past few years (i.e. Googling and StackOverflow-ing), I’ve decided to share a method I’ve come up with for setting up TensorFlow.
I dedicate this article to other data scientists who are stuck on looking at command prompts filled with error messages.
Warning: You must have a CUDA®-enabled GPU card.
Install (in order):
Visual Studio
Anaconda
NVIDIA CUDA Toolkit + cuDNN
Before all else, install Visual Studio from here. Install the Community version because Professional and Enterprise require a subscription.
Note: Visual Studio is not the same as VS Code IDE!
Download and install Anaconda from here.
You do not have to add Anaconda to PATH environment variable during installation.
After installing Visual Studio, install NVIDIA CUDA Toolkit and cuDNN.
To the current date (October 2020), you must install CUDA 10.1 and cuDNN SDK 7.6 (this is extremely important).
Warning: The supported versions may change so make sure to check out the official TensorFlow docs.
The latest CUDA version is 11 — please visit CUDA Archive and cuDNN Archive for earlier versions.
Install CUDA by simply running the executable file (.exe).
Unzip cuDNN library and move all the files to CUDA directory. If you haven’t changed the installation directory, your CUDA will be located here:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA
Open Anaconda Prompt and check the version of Python.
You can enter the command below to check the version of Python you are currently running.
python --version
Then, create a new Anaconda virtual environment:
conda create -n tf python=PYTHON_VERSION
tf can be changed to any other name (e.g. python_tensorflow)
Remember to replace PYTHON_VERSION with your Python version (e.g. 3.8.5)
Then, activate the environment you have just created:
conda activate tf
Finally, install TensorFlow:
pip install tensorflow
Do not pip install tensorflow-gpu as it will install an older version of TensorFlow (old tutorials on YouTube use this command).
Test if TensorFlow has been installed correctly and if it can detect CUDA and cuDNN by running:
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
If there are no errors, congratulations — you have successfully installed TensorFlow.
I personally use Jupyter Notebook, Seaborn, and Matplotlib a lot, so I make sure to install these libraries by running:
pip install jupyter ipykernel seaborn matplotlib
Add the Anaconda environment you have created earlier to Jupyter Notebook.
python -m ipykernel install --user --name ENVIRONMENT_NAME --display-name "KERNEL_DISPLAY_NAME"
Return to the base conda environment and open up Jupyter Notebook:
conda activate basejupyter notebook
Create a new Jupyter Notebook and open it up:
Run these three lines of code below:
!python --versionimport tensorflow as tfprint("Num GPUs Available", len(tf.config.experimental.list_physical_devices('GPU')))
If it can detect your Python and your GPU, you have successfully installed TensorFlow (GPU) and essential tools for machine learning!