On this article we will discuss how to install TensorFlow on Linux Ubuntu 20.04 LTS operating system.
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.
- 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)
Fortunately, on our system Python has been installed from various versions. To check it can be done with the following command line:
ptyhon --version or python3.9 version or
TensorFlow Installation Steps
At least, there are 3 steps for TensorFlow installation, namely: install the Python development environment, create a virtual environment and install the TensorFlow pip package.
1. Install the Python development environment
We will use the Python environment as the place where TensorFlow will be installed and operated, so we must prepare the Python environment first. Here are the steps that we will go through in this step.
1.1 Update Ubuntu 20.04 LTS system
We will update the system by submitting the command line:
sudo apt update.
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
1.2. Install Python3 Environment
Installating Pyhton Environment by using command line :
sudo apt install python3-dev python3-venv.
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
2. Create a virtual environment
On this step we will create an environment where TensorFlow will be running. For this purpose, we must prepare a new directory that will be used by the TensorFLow environment. On this example, we will create a new directory called as
oto_tensor located on my home directory.
ramans@otodiginet:~$ pwd /home/ramans ramans@otodiginet:~$ mkdir oto_tensor ramans@otodiginet:~$ cd oto_tensor/ ramans@otodiginet:~/oto_tensor$ pwd /home/ramans/oto_tensor ramans@otodiginet:~/oto_tensor$ python3 -m venv oto_venv ramans@otodiginet:~/oto_tensor$ source oto_venv/bin/activate
The we install pip inside the environment by submitting command line :
pip install --upgrade pip. TensorFLow requires pip version 19 or above to operational, and on our environment we had pip verisn 21.1.2.
(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) |████████████████████████████████| 1.5 MB 522 kB/s 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. Install TensorFlow on
Now, our environment has been fully functional, then we will install TensorFlow on our system by submitting command line :
pip install --upgrade tensorflow.
(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
Follow all the installation process until completion. After the TensorFlow installation is complete we can validate it by querying the TensorFlow’s version, with the following command line :
python -c 'import tensorflow as tf; print(tf.version)'. The output should be
(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
So far TesorFlow installation was completed done successfully.
TensorFlow is a framework for building machine learning. All about TensorFlow can be found on its official website. Have a nice day, stay safe.