Custom Installation

The install_tensorflow() function is provided as a convenient way to get started, but is not required. If you have an existing installation of TensorFlow or just prefer your own custom installation that’s fine too.

The full instructions for installing TensorFlow on various platforms are here: https://www.tensorflow.org/install/. After installing, please refer to the sections below on locating TensorFlow and meeting additional dependencies to ensure that the tensorflow for R package functions correctly with your installation.

Locating TensorFlow

Once you’ve installed TensorFlow you need to ensure that the tensorflow for R package can find your installation. The package scans the system for various versions of Python, and also scans available virtual environments and conda environments, so in many cases things will just work without additional effort.

If the version of TensorFlow you installed is not found automatically, then you can use the following techniques to ensure that TensorFlow is located.

Specify the RETICULATE_PYTHON environment variable to force probing within a specific Python installation. For example:

Sys.setenv(RETICULATE_PYTHON="/usr/local/bin/python")
library(tensorflow)

You could also add the RETICULATE_PYTHON environment variable to your .Rprofile or .Renviron.

Alternatively, call the use_python() family of configuration functions:

Function Description
use_python() Specify the path a specific Python binary.
use_virtualenv() Specify the directory containing a Python virtualenv.
use_condaenv() Specify the name of a conda environment.

For example:

library(tensorflow)
use_virtualenv("my_env")

Additional Dependencies

There are some components of TensorFlow (e.g. the Keras library) which have dependencies on additional Python packages. The install_keras() function installs these dependencies automatically, however if you do a custom installation you should be sure to install them manually.

You can install the additional dependencies with the following command in terminal (or in repl_python() with the %pip magic):

pip install tensorflow-hub tensorflow-datasets scipy requests Pillow h5py pandas pydot

Supported Platforms

Note that binary installations of TensorFlow are provided for Windows, OS X, and Ubuntu 16.04 or higher. It’s possible that binary installations will work on other Linux variants but Ubuntu is the only platform tested and supported.