Setting up nvidia cuda for tensorflow in debian


In this article I describe how to set up supported Nvidia hardware to work with debian, by the end you should be able to run a tensorflow tutorial on the video card. I ran this tutorial on Nvidia GTX 1060 6GB.

This tutorial uses CUDA kit packaged by Debian project and not the one provided by Nvidia for Ubuntu

This is a part of the talk I gave at August 2019 GTALUG meeting. I've been coming back to the video for the various bits of settings and perhaps having this written down would be more useful.


The following is needed to successfully run tensorflow-gpu. See tensorflow website for updated list & details.

  • NVIDIA GPU drivers
  • CUDA toolkit
  • CUPTI ships with CUDA toolkit
  • cuDNN SDK

Library installation

Add non-free repository to your /etc/apt/sources.list if you haven't already

deb buster main contrib non-free
deb-src buster main contrib non-free

Run apt update & upgrade as a superuser

# apt update
# apt upgrade

Install CUDA package

# apt install nvidia-cuda-dev nvidia-cuda-toolkit  nvidia-driver

Install CUDDN package

Unfortunately the license for the package doesn't allow it to be distributed by the third-party, like debian repos, so you will have to register fill out survey on nvidia website in order to download the package.

The discussion on detailed issues preventing packaging this can be found at this page --

Once downloaded, install the package with the following command

# dpkg -i libcudnn6_6.0.20-1_cuda8.0_amd64.deb

Tensorflow installation

Create a Python 3 virtual environment and install tensorflow and tensorflow-gpu packages with the following command

$ pip install tensorflow tensorflow-gpu

Clone tensorflow models tutorial and attempt to run script

$ git clone
$ cd models/tutorials/image/imagenet
$ python3

I theory, at this point the classification script should work, however in practice it doesn't.

You will be greeted with errors related to missing libraries. These errors, however, are fairly straightforward to fix -- some of the library files are in place that tensorflow package doesn't expect. This can be mitigated by creating several symlinks, as described in the next section.

Library troubleshooting

The first error running will throw the following:

Could not dlopen library '';
cannot open shared object file:
No such file or directory

This file is provided by libcudart10.1. To find which package provides this file I use apt-file utility that lets you to search for a particular file among all available packages.

Attempting to install the package it would reveal that it is already present.

# apt install libcudart10.1
Reading package lists... Done
Building dependency tree
Reading state information... Done
libcdart10.1 is already the newest version (10.1.105-2).
libcudart10.1 set to manually installed.

The only other way to fix it is to create a symlink from the version 10.1 to the version required by tensorflow - 10.0.

If you try to re-run the classifier, you will encounter the same error caused by a different library requirement. The snippet below should fix all errors like this.

# cd /usr/lib/x86_64-linux-gnu
# ln -s
# ln -s
# ln -s
# ln -s
# ln -s
# ln -s

Running again will now run successfully and produce desired result.

giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.89107)
indri, indris, Indri indri, Indri brevicaudatus (score = 0.00779)
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00296)
custard apple (score = 0.00147)
earthstar (score = 0.00117)


Here is the video presentation of the material.