How to Install TensorFlow 2.0 on Anaconda (with CUDA support)

TensorFlow 2.0 has been released for a few months now. This latest version comes with many new features and improvements, such as eager execution, multi-GPU support, tighter Keras integration, and new deployment options such as TensorFlow Serving.

So, it’s time we all switched to TensorFlow 2.0.

The Anaconda-native TensorFlow 2.0 packages are now available in the main conda repository. So, let’s see how we can install TensorFlow 2.0 on Anaconda Python. This method will work on both Windows and Linux. And, if you have a CUDA capable NVIDIA GPU, you can enable GPU support as well.

Step 1.Creating a New Conda Environment

We’ll start by creating a new conda environment. (I’ll name it ‘tensorflow2’. You can choose another name if you like):

conda create --name tensorflow2 python=3.7 anaconda
Create a new conda environment

When prompted, select yes to proceed with the package download and installation, as usual with any other conda environment creation,

Select yes to proceed with the installation

Once the environment is created you can activate it using,

conda activate tensorflow2

(Make sure to substitute ‘tensorflow2’ with the environment name you used)

Activate the new environment

Step 2: Installing the TensorFlow Conda Package

Once the environment is activated, we can install TensorFlow by running,

conda install tensorflow

for the CPU version.

conda install tensorflow-gpu

For the GPU version.
If you have a NVIDIA GPU, I highly recommend you install the GPU version.

Install the TensorFlow Conda Package

Conda will take care of installing all the dependencies for you. If you opted to install the GPU version, this will also include the CUDA Toolkit and cuDNN libraries as well.

CUDA Toolkit and cuDNN dependencies being installed

Step 3: Verifying the Installation

Once the installation completes, you can run the ‘conda list‘ command to view the packages installed.

Run ‘conda list’ to view the installed packages

You’ll see the TensorFlow 2.0 packages which just got installed, as well as the CUDA packages the got installed (if you installed the GPU version).

CUDA Toolkit and cuDNN installed

Once you have verified all the packages in the list, we can run a final verification step to see whether TensorFlow starts up by running,

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

Run the TensorFlow verification step

You may see few initialization steps being printed on to the console (The messages would differ on whether you have the GPU or the CPU version). It should end with printing something like this,

tf.Tensor(-1143.305, shape=(), dtype=float32)

(The actual values will be different, as we use a random value as input)

Verification is complete

If the verification step runs without an error, then we’re good to go.

Happy TensorFlow 2.0 programming!

Related Links:

TensorFlow 2.0 Released!
TensorFlow 2.0 Official Release Announcement



, , , ,




Leave a Reply

Your email address will not be published. Required fields are marked *