Installation Guide for TensorFlow 2.0
May 21, 2020 • 8 Minute Read
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:
sudo yum install epel-release -y
Step 2: After enabling the EPEL repository, install the pip package with the command below:
sudo yum install python3-pip -y
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.
pip3 –-version
Step 4: Upgrade to the latest version using this command:
pip3 install --upgrade pip
Step 4b: Verify the pip version with the command below:
pip3 –-version
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:
sudo apt-get update
Step 2: Install pip using the following command with Python 3:
sudo apt-get install python3-dev python3-pip -y // python3
Step 3: Verify the pip version with the command below. If version is 19 or greater, as stated above, skip step 4. Otherwise, proceed.
pip3 –-version
Step 4: Upgrade to the latest version using this command:
pip3 install --upgrade pip
Installing pip and Python on MacOS
Step 1: Download the installation script using the following command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step 2: Create path using the command below:
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
Step 3: Update your operating system packages using the command below:
brew update
Step 4: Install python packages with the command below. Please note this comes with pip package.
brew install python
Installation of TensorFlow on Linux OS (CentOS and Ubuntu) / MacOS
Step 1: Install TensorFlow using the following commands:
pip3 install --user --upgrade tensorflow
Step 2: Run the code below to verify TensorFlow installation:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([10, 10])))"
Output:
The result:
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.
https://aka.ms/vs/16/release/vc_redist.x64.exe
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.
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.
Select the Enabled radio button as shown below.
Finally, click ok to see the enabled page as shown below.
Step 3a: Download and install Python 3 using the link below:
https://www.python.org/downloads/release/python-382/
Step 3b: Check Add Python to PATH and click on Install Now.
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.
Step 5: Upgrade to the latest version using this command:
pip3 install --upgrade pip
Step 5: Verify the pip version install using the following command:
pip3 --version
Output:
Installing TensorFlow on Windows Operating System
Step 1: Install TensorFlow using the following commands:
pip3 install --user --upgrade tensorflow
Additional packages installed:
Step 2: Run the code below to verify TensorFlow installation:
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([100, 100])))"
Output:
The result:
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.