How to Install TensorFlow via Precompiled Packages

By Matthew Scarpino

Google provides two methods for installing TensorFlow, and the simpler option involves installing precompiled packages. This discussion presents a three-step process for installing these packages:

  1. Install Python on your development system.
  2. Install the pip package manager.
  3. Use pip to install TensorFlow.

The second installation method involves compiling TensorFlow from its source code. This option takes time and effort, but you can obtain better performance because your TensorFlow package will take the fullest advantage of your processor’s capabilities.

Install Python and pip/pip3

TensorFlow supports development with Java and C++, but this discussion focuses on Python. Python 3 is used in the example code, but you’re welcome to use Python 2.

Python’s official package manager is pip, which is a recursive acronym that stands for “pip installs Python.” To install packages like TensorFlow, you can use pip on Python 2 systems or pip3 on Python 3 systems. Package management commands have the following format:

pip <command-name> <command-options>

pip and pip3 accept similar commands and perform similar operations. For example, executing pip list or pip3 list prints all the Python packages installed on your system. The table lists this and five other commands.

Package Management Commands

Command Name Description
install Installs a specified package
uninstall Uninstalls a specified package
download Downloads a package, but doesn’t install it
list Lists installed packages
show Prints information about a specified package
search Searches for a package whose name or summary contains the given text

For this discussion, the most important command to know is pip install and pip3 install. But keep in mind that pip/pip3 can perform many other operations.

If you execute a TensorFlow application using a precompiled package, you may receive messages like “The TensorFlow library wasn’t compiled to use XYZ instructions, but these are available on your machine and could speed up CPU computations.” To turn off these messages, create an environment variable named TF_CPP_MIN_LOG_LEVEL and set its value to 3.

Installing on Mac OS

Many versions of Mac OS have Python already installed, but you should obtain and install a new Python package. If you visit Python Software Foundation, you see one button for Python 2 and another for Python 3. If you click one of these buttons, your browser downloads a PKG file that serves as the Python installer.

When you launch the installer, the Python installation dialog box appears. To install the package, follow these five steps:

  1. In the Introduction page, click the button labeled Continue.
  2. In the Read Me page, click the button labeled Continue.
  3. In the License page, click the button labeled Continue and then click Agree to accept the software license agreement.
  4. In the Installation Type page, click Install to begin the installation process, entering your password, if necessary.
  5. When the installation is complete, click Close to close the dialog box.

If the installation completes successfully, you can run pip or pip3 on a command line. You can install TensorFlow with the following command:

pip install tensorflow

This command tells the package manager to download TensorFlow, TensorBoard, and a series of dependencies. One dependency is six, which supports compatibility between Python 2 and 3. If the installation fails due to a preinstalled six package, you can fix the issue by executing the following command:

pip install --ignore-installed six

This command tells pip to install six on top of the existing installation. After this installation completes, you should be able to run pip install tensorflow without error. On the system used here, the installer stores the TensorFlow files in the /Library/Frameworks/Python.framework/Versions/<ver>/lib/python<ver>/site-packages/tensorflow directory.

Installing on Linux

Many popular distributions of Linux are based on Debian, including Ubuntu and Linux Mint. These distributions rely on the Advanced Package Tool (APT) to manage packages, which you can access on the command line by entering apt-get. This discussion explains how to install TensorFlow on these and similar operating systems.

Most Linux distributions already have Python installed, but it’s a good idea to install the full development version and pip/pip3. The following command installs both for Python 2:

sudo apt-get install python-pip python-dev

Alternatively, the following command performs the installation for Python 3:

sudo apt-get install python3-pip python3-dev

After installation completes, you should be able to execute pip or pip3 on the command line. The following command installs the TensorFlow package and its dependencies (use pip3 for Python 3):

sudo pip install tensorflow

This command installs TensorFlow, TensorBoard, and their dependencies. On an Ubuntu system, the installer stores the files in the /usr/local/lib/python<ver>/dist-packages/tensorflow directory.

Installing on Windows

For Windows users, TensorFlow’s documentation specifically recommends installing a 64-bit version of Python 3.5. To download the installer, visit Python Software Foundation, find a version of Python 3, and click the link entitled Windows x86-64 executable installer. This downloads an *.exe file that serves as the installer.

When you launch the installer, the Python setup dialog box appears. The following steps install Python on your system:

  1. Check the checkbox for adding the Python installation directory to the PATH variable.
  2. Click the link labeled Install Now.
  3. When installation finishes, click the Close button to close the installer.

After you install Python, you should be able to run pip3 on a command line. You can install TensorFlow with the following command:

pip3 install tensorflow

The package manager downloads TensorFlow, TensorBoard, and the packages’ dependencies. On my Windows system, the installer stores the files to the C:\Users\<name>\AppData\Local\Programs\Python\Python<ver>\Lib\site-packages\tensorflow directory.