Tensorflow in R

reticulate
tensorflow

#1

Hello,

I am trying to install tensorflow in R. I am able to install tensorflow package through github devtools::install_github(“rstudio/tensorflow”). But when i am trying to install the tensorflow by using
install_tensorflow() function, I am encountering with the following error.

library(tensorflow)

reticulate::use_python("/opt/local/tools/python/Python-3.6.3/bin/python3.6")
install_tensorflow()
Error: Prerequisites for installing TensorFlow not available.
Please install the following Python packages before proceeding: pip, virtualenv

Does this error means to install the pip, virtualenv packages in R or it should be installed in python version. This packages are already installed in our python which is installed under /opt/local/tools/python/Python-3.6.3/bin/python3.6

The default system level python is installed under /usr/bin/python .

Could anyone help me how to get resolve this error ?

Thanks in advance!


#2

It means you need to install the python versions.

Are you on linux system? In that case the below may help which is taken from a Docker file that installs R Tensorflow, and if you are say on MacOS then it should at least point you in the right direction, but I guess you need homebrew or similar:

# install cron and nano and tensorflow and tflearn
RUN apt-get update && apt-get install -y \
    cron nano \
    python-pip python-dev libhdf5-dev \
    && pip install cython \
    && pip install numpy \
    && pip install pandas \
    && export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.0-cp27-none-linux_x86_64.whl \
    && pip install --upgrade $TF_BINARY_URL \
    && pip install git+https://github.com/tflearn/tflearn.git \

    && pip install feather-format \
    && pip install h5py \


#3

I am not sure whether this is the correct solution, but I installed Anaconda Python 3.6 and then installed tensorflow in python using

conda install tensorflow

All dependencies were installed.
Then I installed keras in Python using

pip install keras

This was followed by

install.packages(keras)

in R which included tensorflow as a dependency. Now I can use keras from R without any errors. I have not used tensorflow explicitly.


#4

Hi,

Out of curiosity any reason why you chose to use both pip and conda to install keras and tensorflow instead of just conda or pip alone ?


#5
conda install keras 

does not work.

pip install keras 

works.

Apparently

conda install -c conda-forge keras tensorflow

should work but I did not use it.


#6

The previous answers suggested that you install TensorFlow using Python tools like pip and conda.

However, the R package tensorflow makes this very easy, and will install all of the Python dependencies using a built-in function:

library(tensorflow)
install_tensorflow()