In this tutorial, we are going to set up TensorFlow in a virtual Python environment on Ubuntu 18.04. Developed by the Google Brain team, TensorFlow is an open-source framework designed as a high-level interface for implementing machine learning and mathematical operations.
This library provides developers with 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.
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.
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 -yStep 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 system’s Python environment. Navigate to the directory where you want your project to exist and run this command:
python3 -m venv venvThis 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/activateYour 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 pipStep 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 setuptoolsStep 5: Install TensorFlow
Finally, install TensorFlow:
(venv) root@ubuntu:~# pip install tensorflowJoin Us!
Luckily, Liquid Web has some of the most powerful servers in the hosting industry, with virtual servers optimized for Ubuntu, Linux, and cPanel. 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?
Justin Palmer