Install CUDA 10.1, Anaconda and TensorFlow on Linux Mint 19.3

by Ugnius Malūkas

In order to install TensorFlow for Nvidia GPU (418.x+), Nvidia CUDA is needed. TensorFlow (2.1.0+) only supports Nvidia CUDA 10.1. That is why the newest CUDA version cannot be used here.

I use Anaconda because it helps to separate Python versions from system ones and manage dependencies without writing them into Linux system folders.

Install CUDA

Installation

Be sure that you have already installed Nvidia GPU drivers. My recommendation is to install it through the Driver Manager.

If you need to install CUDA, cuDNN and TensorRT without APT repository, follow this tutorial: Install CUDA 10.1 without APT repostory on Linux Mint 19.3.

1) Add NVIDIA package repositories

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.1.243-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804_10.1.243-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo apt-get update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt-get update

2) Reboot your computer:

$ sudo reboot

3) Check if GPU are visible using nvidia-smi command:

$ nvidia-smi

4) Install CUDA and cuDNN:

sudo apt-get install --no-install-recommends \
    cuda-10-1 \
    libcudnn7=7.6.4.38-1+cuda10.1  \
    libcudnn7-dev=7.6.4.38-1+cuda10.1

5) Install TensorRT required by TensorFlow:

sudo apt-get install -y --no-install-recommends libnvinfer6=6.0.1-1+cuda10.1 \
    libnvinfer-dev=6.0.1-1+cuda10.1 \
    libnvinfer-plugin6=6.0.1-1+cuda10.1

Install TensorFlow with Anaconda

1) Download Anaconda for Python 3.7 from https://www.anaconda.com/distribution/#linux.

2) Run the installation:

$ chmod u+x Anaconda3-X.Y.Z-Linux-x86_64.sh
$ ./Anaconda3-X.Y.Z-Linux-x86_64.sh

3) In the end of Anaconda installation write yes when Anaconda asks “Do you wish the installer to initialize Anaconda3 by running conda init?“.

4) Optional: When Anaconda is installed, it is activated by default when a new terminal is open. To prevent this, use this command:

$ conda config --set auto_activate_base false

5) Close and open terminal.

6) Create TensorFlow environment for Python 3.7:

$ conda create -n tensorflow python=3.7

7) Activate the created environment:

$ conda activate tensorflow

8) Install TensorFlow GPU version

(tensorflow)$ pip install tensorflow-gpu

Verify Installation

1) For verifying TensorFlow installation, one of options is to use ipython. If it is not installed, use this command:

(tensorflow)$ pip install ipython.

2) Open ipython:

(tensorflow)$ ipython

3) Check if TensorFlow is installed and a GPU is being used:

(tensorflow)$ pip install ipython.

In [1]: import tensorflow as tf 
   ...: print(tf.test.is_built_with_cuda())  

The result should be similar to this output:

ipython output

Reference List

Tested on