Author avatar

Omotayo Aina

Installation Guide for TensorFlow 2.0

Omotayo Aina

  • May 21, 2020
  • 8 Min read
  • 2,921 Views
  • May 21, 2020
  • 8 Min read
  • 2,921 Views
Data
Data Analytics
Machine Learning
TensorFlow

Introduction

TensorFlow is an end-to-end open source machine learning platform used for machine learning and deep learning applications. The Google team developed TensorFlow to develop and research fascinating ideas on artificial intelligence. TensorFlow is created using the Python programming language, making it an easy-to-understand framework.

In this guide, you'll learn how to install pip and TensorFlow 2 packages on commonly used operating systems such Linux (CentOS and Ubuntu Linux), Windows (Windows 10) and MacOS.

Pip, short for “Pip installs packages”, is a standard package management system that simplifies installation and management of software packages written in Python, such as those found in the Python Package Index (PyPI).

Below are the steps to install the TensorFlow 2 package. Please note that the latest TensorFlow version (Version 2) comes with both CPU and GPU flavors bundled together, and GPU is used by default. Expect a warning about libnvinfer packages not being found if you are not on a GPU-supported machine. You can ignore this warning the as CPU flavor will be use by the TensorFlow framework on the machine. You can install TensorRT to fix this warning, but that installation is beyond our scope of this guide.

Available TensorFlow 2 Packages

  • TensorFlow: the latest stable release with CPU and GPU support (Ubuntu and Windows)
  • tf-nightly: Preview build (unstable). Ubuntu and Windows include GPU support.

System Requirements

  • Python 3.5–3.7
  • pip 19.0 or later (requires manylinux2010 support)
  • Ubuntu 16.04 or later (64-bit)
  • macOS 10.12.6 (Sierra) or later (64-bit) (no GPU support)
  • Windows 7 or later (64-bit) (Python 3 only)
    • Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019
  • Raspbian 9.0 or later
  • GPU support requires a CUDA®-enabled card (Ubuntu and Windows)

TensorFlow is tested and supported on the following 64-bit systems:

  • Python 3.5–3.7
  • Ubuntu 16.04 or later
  • Windows 7 or later
  • macOS 10.12.6 (Sierra) or later (no GPU support)
  • Raspbian 9.0 or later

Note: TensorFlow 2 packages require a pip version later than 19.0.

Installation on Linux OS/MacOS

Installing pip on CentOS for Python Version 3

Step 1: Pip is available in some CentOS versions but not in CentOS7. To install pip on CentOS, enable the EPEL repository with the command below:

1
sudo yum install epel-release -y
CentOS

Output: six

Step 2: After enabling the EPEL repository, install the pip package with the command below:

1
sudo yum install python3-pip -y
CentOS

Output: seven

Step 3: Verify the pip version with the command below. If the version is 19 or higher, as stated above, skip step 4, Otherwise, proceed.

1
pip3 –-version
CentOS

Output: eight

Step 4: Upgrade to the latest version using this command:

1
pip3 install --upgrade pip
CentOS

Output: nine

Step 4b: Verify the pip version with the command below:

1
pip3 –-version
CentOS

Output: ten

Installing Pip on Ubuntu

Step 1: Pip is not available in Ubuntu. To install pip on Ubuntu, you first need to start by updating your operating system package list using the following command:

1
 sudo apt-get update
Ubuntu

Step 2: Install pip using the following command with Python 3:

1
sudo apt-get install python3-dev python3-pip -y // python3
Ubuntu

Step 3: Verify the pip version with the command below. If version is 19 or greater, as stated above, skip step 4. Otherwise, proceed.

1
pip3 –-version
Ubuntu

Step 4: Upgrade to the latest version using this command:

1
pip3 install --upgrade pip
Ubuntu

Installing pip and Python on MacOS

Step 1: Download the installation script using the following command:

1
[/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"]
MacOS

Step 2: Create path using the command below:

1
[export PATH="/usr/local/bin:/usr/local/sbin:$PATH"]
MacOS

Step 3: Update your operating system packages using the command below:

1
brew update
MacOS

Step 4: Install python packages with the command below. Please note this comes with pip package.

1
brew install python
MacOS

Installation of TensorFlow on Linux OS (CentOS and Ubuntu) / MacOS

Step 1: Install TensorFlow using the following commands:

1
pip3 install --user --upgrade tensorflow
Linux

Output: twenty-one-a

Additional packages installed: twenty-one-b

Step 2: Run the code below to verify TensorFlow installation:

1
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([10, 10])))"
Linux

Output:

twenty-two

The result:

twenty-three

Installation on Windows OS

Installing pip on Windows Operating System

Installing pip on Windows Operating System can be a little tricky, but it's also very simple.

Starting with TensorFlow version 2.1.0, the msvcp140_1.dll file is required. It may not be provided in older redistributable packages, but it comes with Visual Studio 2019 and can be installed separately. Download it separately if you are using an older version of Visual Studio. In this guide, however, we will use the newer version right from the Microsoft page.

Step 1: Download and install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017, and 2019 using the link below.

1
https://aka.ms/vs/16/release/vc_redist.x64.exe
Windows

eleven

eleven

Step 2: Enable long paths on your Windows operating system by following the below instructions:

To do this, first hit the Windows key, type gpedit.msc, and press Enter.

twelve

Next, navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem > NTFS.

Double click the Enable NTFS long paths option as shown below and enable it.

thirteen

Select the Enabled radio button as shown below.

fourteen

Finally, click ok to see the enabled page as shown below.

fifteen

Step 3a: Download and install Python 3 using the link below:

1
https://www.python.org/downloads/release/python-382/
Windows

sixteen

Step 3b: Check Add Python to PATH and click on Install Now.

seventeen

Step 4: Verify the pip version with the command below on command prompt, and if the version is 19 or higher, as stated above, skip step 5. Otherwise, proceed.

eighteen

Step 5: Upgrade to the latest version using this command:

1
pip3 install  --upgrade pip
Windows

Output: nineteen

Step 5: Verify the pip version install using the following command:

1
pip3 --version
Windows

Output:

twenty

Installing TensorFlow on Windows Operating System

Step 1: Install TensorFlow using the following commands:

1
pip3 install --user --upgrade tensorflow
Windows

twenty-four-a

Additional packages installed:

twenty-four-b

Step 2: Run the code below to verify TensorFlow installation:

1
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([100, 100])))"
Windows

Output:

twenty-five

The result:

twenty-six

Conclusion

This guide explained how to install TensorFlow version 2.0 on Linux Operating Systems, MacOS, and Windows machines using the pip command with Python 3.

TensorFlow is a machine learning framework developed by Google and used for the development of deep learning models. The previous version of TensorFlow comes in two flavors, CPU-only and GPU-supported versions. The latter is more powerful and more suitable for image processing tasks. But the current version of TensorFlow includes both flavors, which means you don't have to install them separately.

12