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.
TensorFlow is tested and supported on the following 64-bit systems:
Note: TensorFlow 2 packages require a pip version later than 19.0.
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:
1sudo yum install epel-release -y
Output:
Step 2: After enabling the EPEL repository, install the pip package with the command below:
1sudo yum install python3-pip -y
Output:
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.
1pip3 –-version
Output:
Step 4: Upgrade to the latest version using this command:
1pip3 install --upgrade pip
Output:
Step 4b: Verify the pip version with the command below:
1pip3 –-version
Output:
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
Step 2: Install pip using the following command with Python 3:
1sudo 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.
1pip3 –-version
Step 4: Upgrade to the latest version using this command:
1pip3 install --upgrade pip
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)"]
Step 2: Create path using the command below:
1[export PATH="/usr/local/bin:/usr/local/sbin:$PATH"]
Step 3: Update your operating system packages using the command below:
1brew update
Step 4: Install python packages with the command below. Please note this comes with pip package.
1brew install python
Step 1: Install TensorFlow using the following commands:
1pip3 install --user --upgrade tensorflow
Output:
Additional packages installed:
Step 2: Run the code below to verify TensorFlow installation:
1python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([10, 10])))"
Output:
The result:
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.
1https://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:
1https://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:
1pip3 install --upgrade pip
Output:
Step 5: Verify the pip version install using the following command:
1pip3 --version
Output:
Step 1: Install TensorFlow using the following commands:
1pip3 install --user --upgrade tensorflow
Additional packages installed:
Step 2: Run the code below to verify TensorFlow installation:
1python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([100, 100])))"
Output:
The result:
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.