Reading Time: 2 minutes

In this tutorial, we are going to set up TensorFlow in a virtual Python environment on Ubuntu 18.04. TensorFlow is an open-source framework, developed by the Google Brain team, designed to be a high-level interface for implementing machine learning and mathematical operations. This library provides developers an avenue to work on complex projects like neural networks through an easy to use Python API. One of the significant benefits of having a Python front-end is that it is portable between operating systems like Linux and Windows.

How To Install TensorFlow on Ubuntu 18.04

Typically, the Package Installer for Python or PIP, ships with later distributions of Ubuntu. If for some reason PIP isn't installed on your version of Ubuntu, review this article for Ubuntu 14.04 LTS, How to Install Pip on Ubuntu 14.04 LTS, or this one for Ubuntu 16.04 LTS, How to Install Pip on Ubuntu 16.04 LTS. Additionally, if you happened to end up here, but were looking for information on how to install TensorFlow on Windows, check out this article, Install TensorFlow on Windows.

Pre-flight Check

Python 3.4 or higher must be installed. I will be working through this tutorial as the root user. After step one of this tutorial, it is not technically required to continue as the root user.

Step 1: Install python3-venv

First, ensure that python3-venv is installed. This python module is a requirement to be able to create a Python virtual environment:

apt-get install python3-venv -y

Step 2: Create and activate a Python virtual environment

Rather than installing TensorFlow globally, we will create a Python virtual environment to work within. This prevents any unnecessary modifications to your systems Python environment. Navigate to the directory where you want your project to exist and run this command:

python3 -m venv venv

This command will create a new directory, ./venv that contains a safe Python environment for you to work within. Next, you can activate the virtual Python environment:

source ./venv/bin/activate

Your shell prompt should look something like this now, with (venv) preceding your typical shell prompt:

(venv) root@ubuntu:~#

Step 3: Update PIP

The Python virtual environment you have just created and activated is based on your system's version of Python. In light of this fact, the version of PIP made available to your virtual environment likely needs an update. To update PIP run this command:

(venv) root@ubuntu:~# pip install -U pip

Step 4: Update setuptools

TensorFlow requires the Python package setuptools to be of version 41.0.0 or higher. Run this command to ensure it is updated to the latest version:

(venv) root@ubuntu:~# pip install -U setuptools

Step 5: Install TensorFlow

Finally, install TensorFlow:

(venv) root@ubuntu:~# pip install tensorflow

Join Us!

Luckily, Liquid Web has some of the most powerful servers in the hosting industry. Utilizing TensorFlow to set up a machine learning environment like this can easily be within your reach. You can utilize this technology to gain a leg up in your business intelligence objectives. This then leads to the capability of leveraging AI to push your efforts to the next level! Would you like to know more?

Avatar for Justin Palmer

About the Author: Justin Palmer

Justin Palmer is a professional application developer with Liquid Web

Latest Articles

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article