Introduction
TensorFlow is a free and open-source software library for machine learning and artificial intelligence. It can be used across a range of tasks but has a particular focus on training and inference of deep neural networks. Researchers can develop machine learning and artificial intelligence-related applications with ease using comprehensive tools, libraries, and a community.
In this article, we will explain how to install TensorFlow on Ubuntu 20.04.
Create virtual environment
- Update the package.
$
sudo apt update
- Install supporting packages.
$ sudo apt install software-properties-common
- Add deadnsakes ppa with the below command.
$ sudo add-apt-repository ppa:deadsnakes/ppa
- Refresh the package list again.
$ sudo apt update
- Install python. Here we are Installing python 3.8.
$ sudo apt install python3.8
- Verify the python3 installation.
Output$ python3 --version
Python 3.8.10
- Install Python virtual environment via the venv module on Ubuntu.
$ sudo apt install python3-venv python3-dev
- In your home directory, create a Tensor environment directory.
$ mkdir tensor_env_directory
- You can create a virtual environment with any name of your choice, we are creating a venv name tensor_venv.
$ cd tensor_env_directory
$ python3 -m venv tensor_venv
- After creating the environment, you will need to activate it using the below command.
$ source tensor_venv/bin/activate
Upgrade pip
- You will need to upgrade your pip installer before installing TensorFlow.
$ pip install --upgrade pip
Install TensorFlow
- The TensorFlow-CPU software package is simple to set up and supports CPU workloads.
$ pip install tensorflow-cpu
- Verify the TensorFlow installation.
$ python3 -m pip show tensorflow-cpu
Output
- To verify the TensorFlow installation is working, Run the following command which generates random values.
$ python -c "import tensorflow as tf; print(tf.random.normal([10,10]))"
Output