GPU tensorflow in miniconda on Ubuntu

24 March 2019

Ubuntu and Nvidia drivers

lsb_release -a

will tell you which version of Ubuntu you are running: I am using 18.10 which is the latest as at the time of writing.

sudo lshw -C display | grep product

will tell you what graphics card you are using, so you can double check it is CUDA compatable. I am using a GTX 1050 Ti, which requires the below to install drivers

sudo apt update
sudo apt upgrade
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt install nvidia-driver-410
sudo apt-mark hold nvidia-driver-410
sudo apt install linux-headers-$(uname -r)

Reboot and run


If you get a little table you’re in business!

Miniconda and tensorflow

Let’s now install miniconda and check tensorflow

wget ""
chmod a+x ./

It will ask you some qs during the install process.

Now for the conda magic; note this will take a while while it downloads CUDA, cuddnn, etc, which are extremely large libraries.

conda create --name tf_gpu tensorflow-gpu

So it will take a little while to download them all. When that is done it is time to test by going inside our conda environment and running the python interpreter:

conda activate tf_gpu

In python:

import tensorflow as tf
hello = tf.constant('Hello TF!')
# Below two lines needed if you don't have a graphics card with large amounts of memory
# The GTX 1050 Ti I am using has 4GB and needs the below
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
sess = tf.Session()