This article describes how to install TensorFlow 2.0 in Ubuntu 18 using PIP, the Python package management tool. TensorFlow is a free open-source machine learning library for Python created by Google. Using TensorFlow you can easily train models, test predictions, and create your own machine learning applications.
Ubuntu 18 comes pre-installed with Python 3. This article will describe how to install TensorFlow 2.0 for Python 3 using PIP. The
matplotlib is another useful Python package which you can use to visualise results from machine learning passes, so we’ll describe how to install this as well.
Although Ubuntu 18 comes with Python 3, it does not have PIP installed by default.
You can check if PIP is installed in your system by opening a terminal and entering the following command:
If PIP is installed, you will see the version details printed, for example:
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
If PIP is not installed, you can install it with these commands:
sudo apt update sudo apt install python3-pip
pip3 --versionagain to confirm PIP is installed.
Install TensorFlow 2.0
There are 2 different versions of TensorFlow 2.0, the first is a CPU-only build and the other build includes GPU support.
Note: If you are running Ubuntu in VirtualBox, you will need to install the CPU-only build.
To install the CPU-only build:
pip3 install tensorflow==2.0.0-alpha0
This make take a few minutes depending on your Internet connection.
You can verify the version of TensorFlow that was installed with the following Python command:
python3 -c "import tensorflow as tf; print(tf.__version__)"
You should see the version details printed out, for example:
matplotlib Python package is useful to visualise TensorFlow results from machine learning passes.
First, install the Tkinter module in Ubuntu (which is required by matplotlib):
sudo apt-get install python3-tk
You can verify Tkinter is working with the following Python command:
python3 -c "import tkinter; tkinter._test()"
You should see a window generated, which verifies it is working. Close Quit.
Now, install matplotlib:
pip3 install matplotlib
You can verify
matplotlibis working correctly by generating a simple graph:
python3 -c "import matplotlib.pyplot as p; p.plot(range(20), range(20)); p.show()"
You should see a new window with a basic graph plotted:
Congratulations, that concludes the install of TensorFlow 2.0 in Ubuntu 18 running on VirtualBox.