Install Conda CUDA10.2 cuDNN7.6.5 Pytorch1.3.1 and Tensorflow2.0 in ubuntu 18.04 for deep learning

Source: Deep Learning on Medium

Install Conda CUDA10.2 cuDNN7.6.5 Pytorch1.3.1 and Tensorflow2.0 in ubuntu 18.04 for deep learning

– A complete step by step guide

Photo by Mukil Menon on Unsplash

I got a GPU card at black Friday sales. Got it installed and now would like to update all my SW framework in my Ubuntu 18.04 TLS with the GPU support.

First thing first (assume you already installed the Nvidia driver correctly (otherwise you will often get the GNOME freeze — check out this post if you have this problem:

  1. Anaconda install

Go to the anaconda page check the latest version, for the time of writing, we have the 2019–10 release.

cd /tmp
curl -O

After downloading, verify it.


you should get a correct checksum as something like below:


Everything looks alright, proceed to install


Press enter to continue when asked about accepting the license agreement.

Now we have the conda installed.

check what do we installed with the conda

conda list

you got a long list of packages installed together with Conda

Do a conda update immediately — it will update to the latest version

conda update conda

then update the packages

conda update anaconda

Like to use Anaconda GUI, start the conda navigator


2. Install Nvidia CUDA

Go the NVidia Download package, chose the right combination and follow the command sequence. I recommend to use the local Deb route.

wget mv /etc/apt/preferences.d/cuda-repository-pin-600wget dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.debsudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pubsudo apt-get updatesudo apt-get -y install cuda

After installation is complete, add PATH variable by adding following line to the .bashrc
vim ~/.bashrc
export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
at the end of file.

source the file and make it visible

source ~/.bashrc

do a quick check

cat /proc/driver/nvidia/version
nvcc -V

You are good to Go.

3. Install cuDNN7.6.5

Go to the cuDNN download page (need registration) and select the latest cuDNN 7.6.5 version made for CUDA 10.2. Download the 3 deb file for the ubuntu18.04 and go to the download folder and install from there.

first install the runtime library

sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb

then developer library

sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb

Last the sample codes

sudo dpkg -i libcudnn7-doc_7.6.5.32-1+cuda10.2_amd64.deb

Done. Do a sample code check with the mnistCUDNN

cp -r /usr/src/cudnn_samples_v7/ .
cd cudnn_samples_v7/mnistCUDNN
make clean && make

then run the MNIST classification


You should see the test passed

4. install TF2.0-GPU

Strongly recommended to use conda install for Tensorflow (since you get the conda support now)

first create a conda channel for Tensorflow GPU

conda create --name tf-gpu

then activate the channel

conda activate tf-gpu


conda install -c anaconda tensorflow-gpu

So you get everything for Tensorflow2.0 with GPU in your virtual enviroment now. (note it will downgrade our cuda10.2 to cuda10.0 in the virtual env only -;)

Let’s check the installation

python3 -c 'import tensorflow as tf; print(tf.__version__)'

you should get the 2.0

5. install Pytorch for GPU

First exit from the tf-gpu virtual environment by:

conda deactivate

you should back to your base and then create a Pytorch channel

conda create --name pytorch

activate it

conda activate pytorch

then go the pytorch webpage:

chose the conda version, it is always easier with conda.

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

let’s test it


under python import the PyTorch and check the GPU availability (BTW, Pytorch1.3.1 -the latest PyTorch, is using CUDA10.1-:)

import torch

it should return “true”

Now back to the conda navigator, you should be able to see the two additional channels.