How to Install TensorFlow machine-learning framework on Ubuntu 20.04

TensorFlow is a free and open-source machine-learning platform developed by Google. It helps developers and data scientists to simplify the process of implementing machine-learning models. Currently, it is used by many companies including, PayPal, Intel, Airbus, Twitter and many more. It has a Python front-end and can be portable between operating systems like Linux and Windows.

In this tutorial, we will show you how to install TensorFlow in a Python virtual environment on Ubuntu 20.04.

Prerequisites

  • A server running Ubuntu 20.04.
  • A root password is configured the server.

Getting Started

Before starting, it is recommended to update the system packages to the latest version. You can update them using the following command:apt-get update -y

Once all the packages are updated, you can proceed to the next step.

Install Python and Required Dependencies

Next, you will need to install Python and other required Python dependencies to your server. You can install all of them with the following command:

apt-get install python3 python3-venv python3-dev -y

Once all the packages are installed, run the following command to verify the Python version:

python3 -V

You should get the following output:

Python 3.8.5

Install TensorFlow

In this section, we will show you how to install TensorFlow in Python virtual environment.

First, create a directory for TensorFlow with the following command:

mkdir tensorapp

Next, change the directory to tensorapp and create a Python virtual environment with the following command:

cd tensorapp
python3 -m venv venv

Next, activate the virtual environment with the following command:

source venv/bin/activate

Next, upgrade the pip package to the latest version with the following command:

(venv) root@ubuntu2004:~/tensorapp# pip install --upgrade pip

You should get the following output:

Collecting pip
  Downloading pip-20.3.3-py2.py3-none-any.whl (1.5 MB)
     |????????????????????????????????| 1.5 MB 13.5 MB/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-20.3.3

Next, install the latest version of TensorFlow using the following command:

(venv) root@ubuntu2004:~/tensorapp# pip install --upgrade tensorflow

Once the installation is completed, verify the TensorFlow installation using the following command:

(venv) root@ubuntu2004:~/tensorapp# python -c 'import tensorflow as tf; print(tf.__version__)'

If everything is fine, you should see the TensorFlow version in the following output:

2.4.0

Next, deactivate from the Python virtual environment with the following command:

(venv) root@ubuntu2004:~/tensorapp# deactivate

Conclusion

Congratulations! you have successfully installed TensorFlow in Python virtual environment on Ubuntu 20.04. For more information, read the TensorFlow guide. 

Share this page:

0 Comment(s)