Install Tensorflow 2.* on Ubuntu 19.10 with GPU support

Dmytro Kisil
5 min readDec 8, 2019

Introduction:

Today I may present you two guides for installing. The first will be for Tensorflow 2.0 and CUDA 10.0 versions. And the second one: for Tensorflow 2.1 and CUDA 10.1(try CUDA 10.2 but failed). CuDNN will be 7.6.5 for both cases. Version 1.15 is the last 1.x release for Tensorflow, so I’m not included this version here.

Notice: As explained here, Tensorflow 2.1 was the first package, which can use with GPU by “pip install tensorflow” — you don’t need to choose between CPU and GPU version (only if concerning about package size). And the last package, supporting Python2 (maybe this could be important for someone). Bonus: added additional section with TensorRT(6.0.1.5 version).

Recommended to use is 2.0 stable version. 2.1.0 is in development — so check it if really want to try this version. After 2.1.0 come I change guide a little to support a final release.

Important change: each block of commands now a copy-paste field. Idea is you could copy few commands and execute them at once (not row by row).

If you will have a problem, try look at more comprehensive guide than that which placed below. So, let’s begin!

Tensorflow 2.0.0 && CUDA 10.0

Remove CUDA:

Delete any previous CUDA version (use if you have any):

sudo apt-get purge nvidia* && sudo apt-get autoremove && sudo apt-get autoclean && sudo rm -rf /usr/local/cuda*

Install CUDA:

Add keys to download (so after apt-get update you got CUDA):

sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub && echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list

Install:

sudo apt-get update && sudo apt-get -o Dpkg::Options::="--force-overwrite" install cuda-10-0 cuda-drivers

Make a reboot now. After add CUDA to path:

echo 'export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}' >> ~/.bashrc && echo 'export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc && source ~/.bashrc && sudo ldconfig

Install cuDNN:

Download newest cuDNN release from here (require log in NVIDIA account). After that click Agree, select “Download cuDNN v7.6.5 (November 18th, 2019), for CUDA 10.0” and choose “cuDNN library for Linux”.

tar -xf cudnn-10.0-linux-x64-v7.6.5.32.tgz && sudo cp -R cuda/include/* /usr/local/cuda-10.0/include && sudo cp -R cuda/lib64/* /usr/local/cuda-10.0/lib64

Install libcupti:

Installed libcupti-dev, added path from this library and reload bashrc:

sudo apt-get install libcupti-dev && echo 'export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc && source ~/.bashrc && sudo ldconfig

Install Tensorflow:

pip3 install tensorflow-gpu==2.0.0

Check Tensorflow:

Run a new terminal and check from python3 shell:

python3
import tensorflow as tf
print(tf.test.is_gpu_available()) -> should return True

Optional: Download TensorRT6 (the latest version for now)

You can found it by link (need register in NVIDIA, as usually). After this you can select TensorRT6 and need to complete a short survey (how would you use this technology). After that click agree to terms and select TensorRT 6.0 GA:

Select “TensorRT 6.0.1.5 GA for Ubuntu 1804 and CUDA 10.0 DEB local repo packages”

Download TensorRT:

sudo dpkg -i nv-tensorrt-repo-ubuntu1804-cuda10.0-trt6.0.1.5-ga-20190913_1-1_amd64.deb && sudo apt-key add /var/nv-tensorrt-repo-cuda10.0-trt6.0.1.5-ga-20190913/7fa2af80.pub

Install TensorRT:

sudo apt-get update && sudo apt-get install tensorrt && sudo apt-get install uff-converter-tf

Check TensorRT:

dpkg -l | grep TensorRT

Tensorflow 2.1.0 && CUDA 10.1

Remove CUDA:

Delete any previous CUDA version (use if you have any):

sudo apt-get purge nvidia* && sudo apt-get autoremove && sudo apt-get autoclean && sudo rm -rf /usr/local/cuda*

Install CUDA:

Add keys to download (so after apt-get update you got CUDA):

sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub && echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list

Install:

sudo apt-get update && sudo apt-get -o Dpkg::Options::="--force-overwrite" install cuda-10-1 cuda-drivers

Make a reboot now. After add CUDA to path:

echo 'export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}' >> ~/.bashrc && echo 'export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc && source ~/.bashrc && sudo ldconfig

Install cuDNN:

Download newest cuDNN release from here (require log in NVIDIA account). After that click Agree, select “Download cuDNN v7.6.5 (November 18th, 2019), for CUDA 10.1” and choose “cuDNN library for Linux”.

tar -xf cudnn-10.1-linux-x64-v7.6.5.32.tgz && sudo cp -R cuda/include/* /usr/local/cuda-10.1/include && sudo cp -R cuda/lib64/* /usr/local/cuda-10.1/lib64

Install libcupti:

Installed libcupti-dev, added path from this library and reload bashrc:

sudo apt-get install libcupti-dev && echo 'export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc && source ~/.bashrc && sudo ldconfig

Install Tensorflow:

At the time when this article wrote, you might can’t install Tensorflow version 2.1.0, because this is only the first release candidate version. But update pip version and setuptools could help. But after update you might see that you will be disable to install any packages through pip anymore — if this happens, uninstall the newest pip version helps.

python3 -m pip install --upgrade pip && python3 -m pip install --upgrade setuptools && python3 -m pip install tensorflow==2.1.0rc0
# Only use if pip is broken:
python3 -m pip uninstall pip

Check Tensorflow:

Run a new terminal and check from python3 shell:

python3
import tensorflow as tf
print(tf.test.is_gpu_available()) -> should return True

Optional: Download TensorRT6 (the latest version for now)

You can found it by link (need register in NVIDIA, as usually). After this you can select TensorRT6 and need to complete a short survey (how would you use this technology). After that click agree to terms and select TensorRT 6.0 GA:

Select “TensorRT 6.0.1.5 GA for Ubuntu 1804 and CUDA 10.1 DEB local repo packages”

Download TensorRT:

sudo dpkg -i nv-tensorrt-repo-ubuntu1804-cuda10.1-trt6.0.1.5-ga-20190913_1-1_amd64.deb && sudo apt-key add /var/nv-tensorrt-repo-cuda10.1-trt6.0.1.5-ga-20190913/7fa2af80.pub

Install TensorRT:

sudo apt-get update && sudo apt-get install tensorrt && sudo apt-get install uff-converter-tf

Check TensorRT:

dpkg -l | grep TensorRT

Conclusion:

Thanks for your attention! Hope that I saved your time. So now you can spend your time and clap article a little if you like it)

--

--