Install TensorFlow with pip

Available packages

  • tensorflow —Current release for CPU-only (recommended for beginners)
  • tensorflow-gpu —Current release 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 with TensorFlow 1.6, binaries use AVX instructions which may not run on older CPUs.
  • Read the GPU support guide to set up a CUDA®-enabled GPU card on Ubuntu or Windows.

1. Install the Python development environment on your system

Check if your Python environment is already configured:

python3 --version
pip3 --version
virtualenv --version

If these packages are already installed, skip to the next step.
Otherwise, install Python, the 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 the 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 the Microsoft Visual C++ 2015 Redistributable Update 3. This comes with Visual Studio 2015 but can be installed separately:

  1. Go to the Visual Studio downloads,
  2. Select Redistributables and Build Tools,
  3. Download and install the Microsoft Visual C++ 2015 Redistributable Update 3.

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

pip3 install -U pip virtualenv

Raspberry Pi

Requirements for the Raspbian operating system:

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

2. Create a virtual environment (recommended)

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

Ubuntu / mac OS

Create a new virtual environment by choosing a Python interpreter and making a ./venv directory to hold it:

virtualenv --system-site-packages -p python3 ./venv

Activate the virtual environment using a shell-specific command:

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

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

Install packages within a virtual environment without affecting the host system setup. Start by upgrading pip:

pip install --upgrade pip

pip list  # show packages installed within the virtual environment

And to exit virtualenv later:

deactivate  # don't exit until you're done using TensorFlow

Windows

Create a new virtual environment by choosing a Python interpreter and making a ./venv directory to hold it:

virtualenv --system-site-packages -p python3 ./venv

Activate the virtual environment:

.\venv\Scripts\activate

Install packages within a virtual environment without affecting the host system setup. Start by upgrading pip:

pip install --upgrade pip

pip list  # show packages installed within the virtual environment

And to exit virtualenv later:

deactivate  # don't exit until you're done using TensorFlow

Conda

Create a new virtual environment by choosing a Python interpreter and making a ./venv directory to hold it:

conda create -n venv pip python=3.6  # select python version

Activate the virtual environment:

source activate venv

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

pip install --ignore-installed --upgrade packageURL

And to exit virtualenv later:

source deactivate

3. Install the TensorFlow pip package

Choose one of the following TensorFlow packages to install from PyPI:

  • tensorflow —Current release for CPU-only (recommended for beginners)
  • tensorflow-gpu —Current release 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)

Virtualenv install

pip install --upgrade tensorflow

Verify the install:

python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

System install

pip3 install --user --upgrade tensorflow  # install in $HOME

Verify the install:

python3 -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

Package location

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

VersionURL
Linux
Python 2.7 CPU-only https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp27-none-linux_x86_64.whl
Python 2.7 GPU support https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp27-none-linux_x86_64.whl
Python 3.4 CPU-only https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp34-cp34m-linux_x86_64.whl
Python 3.4 GPU support https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp34-cp34m-linux_x86_64.whl
Python 3.5 CPU-only https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl
Python 3.5 GPU support https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp35-cp35m-linux_x86_64.whl
Python 3.6 CPU-only https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.12.0-cp36-cp36m-linux_x86_64.whl
Python 3.6 GPU support https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.12.0-cp36-cp36m-linux_x86_64.whl
macOS (CPU-only)
Python 2.7 https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py2-none-any.whl
Python 3.4, 3.5, 3.6 https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl
Windows
Python 3.5 CPU-only https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp35-cp35m-win_amd64.whl
Python 3.5 GPU support https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.12.0-cp35-cp35m-win_amd64.whl
Python 3.6 CPU-only https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp36-cp36m-win_amd64.whl
Python 3.6 GPU support https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.12.0-cp36-cp36m-win_amd64.whl