Install TensorFlow 2 with GPU Support (Dec 2020) for Windows 10 using Conda

Millan Sanchez
2 min readDec 27, 2020

Install NVIDIA Drivers for your GPU.

Install MiniConda for Python 3.8 as TensorFlow at this moment doesn’t support Python 3.9:

Once installed with default options, open the Anaconda Prompt from the applications menu in Windows 10.

First lets install Jupyter Notebooks:

conda install -y jupyter

Then we will create a Virtual Environment for Python 3.7 and TensorFlow:

conda create --name tensorflow-gpu python=3.7

(Python 3.8 is supported by TensorFlow at this moment, but as you will see it will not work to do an automated install)

and then activate the environment by using the following command:

activate tensorflow-gpu

Now lets install Jupyter Notebooks support to this environment:

conda install nb_conda

and agree to install the required components.

Theorically by running the following command the TensorFlow GPU package gets installed with all CUDA and CUDNN libraries but it is not working as Dec 2020 (don’t run this command):

conda install tensorflow-gpu #do not run this command

Currently conda install tensorflow-gpu installs tensorflow v2.3.0 and does NOT install the conda cudnn or cudatoolkit packages. Installing them manually (e.g. with conda install cudatoolkit=11.0) does not seem to fix the problem either.

A solution is to install an earlier version of TensorFlow, which does install cudnn and cudatoolkit, then upgrade with pip. If you follow these steps you don't need to install CUDA or CUDNN in your system using the installers from NVIDIA.

conda install tensorflow-gpu=2.1
pip install tensorflow-gpu==2.3.1

With the conda install tensorflow-gpu=2.1 command it is required to have Python 3.7 and that is the reason we didn’t install Python 3.8 when creating the environment.

Now we want to be able to select this new environment as a Kernel from Jupyter Notebooks. For this to happen run the following line in the prompt:

python -m ipykernel install -- user -- name tensorflow -- display-name "Python 3.7 (with TensorFlow GPU)"

Now lets install some basic and popular libraries to test our environment:

conda install pandas
conda install scikit-learn

That’s it. We are finished.

To test run the following code in a Jupyter notebook, and be sure to select the newly created Kernel:

import sysimport tensorflow.keras
import pandas as pd
import sklearn as sk
import tensorflow as tf
print(f"Tensor Flow Version: {tf.__version__}")
print(f"Keras Version: {tensorflow.keras.__version__}")
print()
print(f"Python {sys.version}")
print(f"Pandas {pd.__version__}")
print(f"Scikit-Learn {sk.__version__}")
gpu = len(tf.config.list_physical_devices('GPU'))>0
print("GPU is", "available" if gpu else "NOT AVAILABLE")

If all goes well you should see the following output:

Tensor Flow Version: 2.3.1
Keras Version: 2.4.0

Python 3.7.9 (default, Aug 31 2020, 17:10:11) [MSC v.1916 64 bit (AMD64)]
Pandas 1.1.5
Scikit-Learn 0.23.2
GPU is available

as you can see GPU is detected and available.

Thanks for reading.

--

--

Millan Sanchez

Business Intelligence, Artificial Intelligence and Data Science.