How to install TensorFlow On Ubuntu 20.04
How to install TensorFlow On Ubuntu 20.04

How To Install Tensorflow On Ubuntu 20.04 LTS

Introduction

TensorFlow is a free and open-source software library for machine learning. TensorFlow is used to train neural networks. It can be used across a range of tasks but has a particular focus on training and inference of deep neural networks. Tensorflow is a symbolic math library based on dataflow and differentiable programming. TensorFlow was developed by the Google Brain team for internal Google use. It was released under the Apache License 2.0 in 2015. On this articel we will discuss how to install TensorFlow on Linux Ubuntu 20.04 LTS operating system.

TensorFlow Installation on Ubuntu 20.04

On this article, we will explain how to install TensorFlow in a Python virtual environment which is running on Linux Ubuntu 20.04 LTS. A virtual environment enable us to have multiple different isolated Python environments on a single computer and install a specific version of a module on a per-project basis, without worrying that it will affect any other Projects.

Prerequisite

  • Ubuntu 20.04 LTS Operating system with sufficient disk space
  • root or an ordinary user access who is having sudo privilege
  • Python 3.6–3.9
    • Python 3.9 support requires TensorFlow 2.5 or later.
    • Python 3.8 support requires TensorFlow 2.2 or later.
  • pip 19.0 or later (requires manylinux2010 support)

TensorFlow Installation Steps :

  1. Install the Python development environment on your system
  2. Create a virtual environment (recommended)
  3. Install the TensorFlow pip package

1. Install the Python development environment

1.1 Update Ubuntu 20.04 LTS system

On this stage, we will update our system to refresh our system pacakges. For this purpose we will submit the command line :

$ sudo apt update

Output :

ramans@otodiginet:~$ sudo apt update
[sudo] password for ramans:
Hit:1 http://ppa.launchpad.net/teejee2008/ppa/ubuntu focal InRelease
Hit:2 http://ppa.launchpad.net/ubuntu-mozilla-daily/ppa/ubuntu focal InRelease
Hit:3 https://dl.yarnpkg.com/debian stable InRelease
Hit:4 http://mirror.telkomuniversity.ac.id/ubuntu focal InRelease
Hit:6 https://deb.nodesource.com/node_14.x focal InRelease
Get:7 http://mirror.telkomuniversity.ac.id/ubuntu focal-updates InRelease [114 kB]

1.2. Install Python3 Environment

On this stage, we will install Pythone environment by submitting command line :

$ sudo apt install python3-dev python3-pip python3-venv

Output :

ramans@otodiginet:~$ sudo apt install python3-venv python3-dev
[sudo] password for ramans:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
libc-dev-bin libc6-dev libcrypt-dev libexpat1-dev libpython3-dev libpython3.8 libpython3.8-dev
libpython3.8-minimal libpython3.8-stdlib linux-libc-dev manpages-dev python-pip-whl
python3-distutils python3-lib2to3 python3.8 python3.8-dev python3.8-minimal python3.8-venv
zlib1g-dev
Suggested packages:
glibc-doc python3.8-doc binutils binfmt-support
The following NEW packages will be installed:
libc-dev-bin libc6-dev libcrypt-dev libexpat1-dev libpython3-dev libpython3.8-dev linux-libc-dev
manpages-dev python-pip-whl python3-dev python3-distutils python3-venv python3.8-dev python3.8-venv
zlib1g-dev
The following packages will be upgraded:
libpython3.8 libpython3.8-minimal libpython3.8-stdlib python3-lib2to3 python3.8 python3.8-minimal
6 upgraded, 15 newly installed, 0 to remove and 192 not upgraded.
Need to get 12.9 MB/19.1 MB of archives.
After this operation, 56.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
setting up python3-distutils (3.8.10-0ubuntu1~20.04) ...
Setting up libpython3.8:amd64 (3.8.5-1~20.04.3) ...
Setting up python3.8-venv (3.8.5-1~20.04.3) ...
Setting up libc6-dev:amd64 (2.31-0ubuntu9.2) ...
Setting up libexpat1-dev:amd64 (2.2.9-1build1) ...
Setting up python3-venv (3.8.2-0ubuntu2) ...
Setting up libpython3.8-dev:amd64 (3.8.5-1~20.04.3) ...
Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1.2) ...
Setting up libpython3-dev:amd64 (3.8.2-0ubuntu2) ...
Setting up python3.8-dev (3.8.5-1~20.04.3) ...
Setting up python3-dev (3.8.2-0ubuntu2) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...

2. Create Virtual Environment

2.1 Create New Directory For VE

On this short tutorial, we will create an new directory called as : oto_tensor, then create a new Python3 environment on it. For this purpose we will submit the following command lines :

$ mkdir oto_tensor
$ cd oto_tensor/

Output :

ramans@otodiginet:~$ pwd
/home/ramans
ramans@otodiginet:~$ mkdir oto_tensor
ramans@otodiginet:~$ cd oto_tensor/
ramans@otodiginet:~/oto_tensor$ pwd
/home/ramans/oto_tensor

2.2 Create Virtual Environment

Then we will create virtual environment by submitting command line :

$ python3 -m venv oto_venv
$ source oto_venv/bin/activate

Output :

ramans@otodiginet:~/oto_tensor$ python3 -m venv oto_venv
ramans@otodiginet:~/oto_tensor$ source oto_venv/bin/activate
(oto_venv) ramans@otodiginet:~/oto_tensor$

3. Install TensorFlow

After setting virtual environment, the we will install TensorFlow. We will perform several tasks for this case as following :

3.1 Upgrade pip

We will upgrade pip to the current version by submitting command line :

$ pip install --upgrade pip

Output :

(oto_venv) ramans@otodiginet:~/oto_tensor$ pip install --upgrade pip
Collecting pip
Using cached pip-21.1.2-py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.0.2
Uninstalling pip-20.0.2:
Successfully uninstalled pip-20.0.2
Successfully installed pip-21.1.2

3.2 Install TensorFlow

After all are set, then we will install TensorFlow by submitting command line :

$ pip install --upgrade tensorflow

Output :

(oto_venv) ramans@otodiginet:~/oto_tensor$ pip install --upgrade tensorflow
Collecting tensorflow
Downloading tensorflow-2.5.0-cp38-cp38-manylinux2010_x86_64.whl (454.4 MB)
|████████████████████████████████| 454.4 MB 13 kB/s
Collecting gast==0.4.0
Downloading gast-0.4.0-py3-none-any.whl (9.8 kB)
Collecting tensorboard~=2.5
  Downloading tensorboard-2.5.0-py3-none-any.whl (6.0 MB)
     |████████████████████████████████| 6.0 MB 2.3 MB/s 
Collecting tensorflow-estimator<2.6.0,>=2.5.0rc0
  Downloading tensorflow_estimator-2.5.0-py2.py3-none-any.whl (462 kB)
     |████████████████████████████████| 462 kB 2.0 MB/s 
Collecting google-pasta~=0.2
  Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB)
     |████████████████████████████████| 57 kB 640 kB/s 
Collecting wheel~=0.35
  Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Collecting numpy~=1.19.2
  Downloading numpy-1.19.5-cp38-cp38-manylinux2010_x86_64.whl (14.9 MB)
     |████████████████████████████████| 14.9 MB 2.4 MB/s 
Collecting astunparse~=1.6.3
  Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Collecting flatbuffers~=1.12.0
  Downloading flatbuffers-1.12-py2.py3-none-any.whl (15 kB)
Collecting h5py~=3.1.0
  Downloading h5py-3.1.0-cp38-cp38-manylinux1_x86_64.whl (4.4 MB)

. . .

Successfully installed absl-py-0.12.0 astunparse-1.6.3 cachetools-4.2.2 certifi-2021.5.30 chardet-4.0.0 flatbuffers-1.12 gast-0.4.0 google-auth-1.31.0 google-auth-oauthlib-0.4.4 google-pasta-0.2.0 grpcio-1.34.1 h5py-3.1.0 idna-2.10 keras-nightly-2.5.0.dev2021032900 keras-preprocessing-1.1.2 markdown-3.3.4 numpy-1.19.5 oauthlib-3.1.1 opt-einsum-3.3.0 protobuf-3.17.3 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.25.1 requests-oauthlib-1.3.0 rsa-4.7.2 six-1.15.0 tensorboard-2.5.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.0 tensorflow-2.5.0 tensorflow-estimator-2.5.0 termcolor-1.1.0 typing-extensions-3.7.4.3 urllib3-1.26.5 werkzeug-2.0.1 wheel-0.36.2 wrapt-1.12.1

3.3 Verifty TensorFlow Installation

After TensorFlow installation was completed done, then we will verify it by submitting command :

$ python -c 'import tensorflow as tf; print(tf.version)'

Output :

(oto_venv) ramans@otodiginet:~/oto_tensor$ python -c 'import tensorflow as tf; print(tf.version)'
2021-06-10 17:13:35.391842: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-06-10 17:13:35.391889: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2.5.0
TensorFlow version 2.5.0

So far, we have reached the final step.

Conclusion

On this short tutorial, we have learnt how to install TensorFlow version 2.5.0 on Ubuntu 20.04 LTS operating system. I hope this article will be helpful.

(Visited 119 times, 1 visits today)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *