TensorFlow Installation Guide – Using Pip to Install TensorFlow

There are many ways to install TensorFlow. This article will provide a detailed guide on how to install TensorFlow using pip.

Available Installation Packages

  • tensorflow — Current version for CPU only (recommended for beginners)

  • tensorflow-gpu — Current version with GPU support (Ubuntu and Windows)

  • tf-nightly — Nightly build for CPU only (unstable)

  • tf-nightly-gpu — Nightly build with GPU support (unstable, Ubuntu and Windows)

System Requirements

  • 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)

  • Raspbian 9.0 or later

Hardware Requirements

  • Starting from TensorFlow 1.6, binaries use AVX instructions, which may not run on older CPUs

  • Refer to the GPU support guide (https://tensorflow.google.cn/install/gpu?hl=zh-CN) to set up a CUDA® supported GPU card on Ubuntu or Windows

Installing Python Development Environment on Your System

Python 3

Check if your Python environment is configured:

Python 3.4, 3.5, or 3.6 is required

$ python3 –version$ pip3 –version$ virtualenv –version

If these packages are installed, proceed to the next step.

Otherwise, install Python, pip package manager, and Virtualenv:

UBUNTU

$ sudo apt update$ sudo apt install python3-dev python3-pip$ sudo pip3 install -U virtualenv # system-wide install

MAC OS

Install using Homebrew package manager:

$ /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”$ export PATH=”/usr/local/bin:/usr/local/sbin:$PATH”$ brew update$ brew install python # Python 3$ sudo pip3 install -U virtualenv # system-wide install

WINDOWS

Install 2015 Redistributable Update 3, which comes with Visual Studio 2015 and can be installed separately:

  • Go to Visual Studio downloads

  • Select Redistributables and Build Tools

  • Download and install Microsoft Visual C++ 2015 Redistributable Update 3

Install the 64-bit Python 3 distribution for Windows (select pip as an optional feature)

C:\> pip3 install -U pip virtualenv

RASPBERRY PI

$ sudo apt update$ sudo apt install python3-dev python3-pip$ sudo apt install libatlas-base-dev # required for numpy$ sudo pip3 install -U virtualenv # system-wide install

OTHER

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py$ python get-pip.py$ sudo pip3 install -U virtualenv # system-wide install

Python 2.7

Check if your Python environment is configured:

$ python –version$ pip –version$ virtualenv –version

If these packages are installed, proceed to the next step.

Otherwise, install Python, pip package manager, and Virtualenv:

UBUNTU

$ sudo apt update$ sudo apt install python-dev python-pip$ sudo pip install -U virtualenv # system-wide install

MAC OS

Install using Homebrew package manager:

$ /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”$ export PATH=”/usr/local/bin:/usr/local/sbin:$PATH”$ brew update$ brew install python@2 # Python 2$ sudo pip install -U virtualenv # system-wide install

RASPBERRY PI

$ sudo apt update$ sudo apt install python-dev python-pip$ sudo apt install libatlas-base-dev # required for numpy$ sudo pip install -U virtualenv # system-wide install

OTHER

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py$ python get-pip.py$ sudo pip install -U virtualenv # system-wide install

Creating a Virtual Environment (Recommended)

Python virtual environments are used to isolate package installations from the system.

UBUNTU / MAC OS

Create a new virtual environment by selecting the Python interpreter and creating a ./venv directory:

$ virtualenv –system-site-packages -p python2.7 ./venv

Activate the virtual environment using shell-specific commands:

$ source ./venv/bin/activate # sh, bash, ksh, or zsh

When virtualenv is active, the shell prompt is prefixed with (venv).

To install packages in the virtual environment without affecting the host system settings, first upgrade pip:

(venv)$ pip install –upgrade pip(venv)$ pip list # show packages installed within the virtual environment

Then deactivate virtualenv:

(venv)$ deactivate # don’t exit until you’re done using TensorFlow

WINDOWS

Create a new virtual environment by selecting the Python interpreter and creating a ./venv directory.

Activate the virtual environment:

(venv)C:\> .envin\activate

Install packages in the virtual environment without affecting the host system settings. First upgrade pip:

(venv)C:\> pip install –upgrade pip(venv)C:\> pip list # show packages installed within the virtual environment

Then deactivate virtualenv:

(venv)C:\> deactivate # don’t exit until you’re done using TensorFlow

CONDA

We recommend using the pip package provided by TensorFlow, but you can also use the community-supported Anaconda package.

Create a new virtual environment by selecting the Python interpreter and creating a ./venv directory:

$ conda create -nvenv pip python=2.7

Activate the virtual environment:

& source activate venv

Within the virtual environment, install the TensorFlow pip package using its full URL:

(venv)$ pip install –ignore-installed –upgrade packageURL

Then deactivate virtualenv:

(venv)$ source deactivate

Installing the TensorFlow pip Package

Select one of the following TensorFlow packages from PyPI for installation:

  • tensorflow — Current version for CPU only (recommended for beginners)

  • tensorflow-gpu — Current version with GPU support (Ubuntu and Windows)

  • tf-nightly — Nightly build for CPU only (unstable)

  • tf-nightly-gpu — Nightly build with GPU support (unstable, Ubuntu and Windows)

Package dependencies are installed automatically. They are all listed under REQUIRED_PACKAGES in the setup.py file.

VIRTUALENV INSTALL

(venv)$ pip install –upgrade tensorflow

Verify the installation:

(venv)$ python -c “import tensorflow as tf; print(tf.__version__)”

SYSTEM INSTALL

$ pip install –user –upgrade tensorflow # install in $HOME

Verify the installation:

$ python -c “import tensorflow as tf; print(tf.__version__)”

Success: TensorFlow is now installed. Read the tutorial to get started. (https://tensorflow.google.cn/tutorials/?hl=zh-CN)

Package Locations

Some installation mechanisms require the URL of the TensorFlow Python package. The value you specify depends on your Python version.

Version

URL

Linux

Python 2.7 CPU-only

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.11.0-cp27-none-linux_x86_64.whl

Python 2.7 GPU support

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.11.0-cp27-none-linux_x86_64.whl

Python 3.4 CPU-only

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.11.0-cp34-cp34m-linux_x86_64.whl

Python 3.4 GPU support

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.11.0-cp34-cp34m-linux_x86_64.whl

Python 3.5 CPU-only

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.11.0-cp35-cp35m-linux_x86_64.whl

Python 3.5 GPU support

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.11.0-cp35-cp35m-linux_x86_64.whl

Python 3.6 CPU-only

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.11.0-cp36-cp36m-linux_x86_64.whl

Python 3.6 GPU support

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.11.0-cp36-cp36m-linux_x86_64.whl

macOS (CPU-only)

Python 2.7

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.11.0-py2-none-any.whl

Python 3.4, 3.5, 3.6

https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.11.0-py3-none-any.whl

Windows

Python 3.5 CPU-only

https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.11.0-cp35-cp35m-win_amd64.whl

Python 3.5 GPU support

https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.11.0-cp35-cp35m-win_amd64.whl

Python 3.6 CPU-only

https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.11.0-cp36-cp36m-win_amd64.whl

Python 3.6 GPU support

https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.11.0-cp36-cp36m-win_amd64.whl

TensorFlow Installation Guide - Using Pip to Install TensorFlow

Leave a Comment