简体   繁体   中英

How to install Tensorflow for R

I had Tensorflow installed with Anaconda. Now I want use it in R and I need to reinstall Tensorflow, because the note here

NOTE: You should NOT install TensorFlow with Anaconda as there are issues with the way Anaconda builds the python shared library that prevent dynamic linking from R.

I already tried to uninstall from Anaconda and install with pip but its came to the same place in anaconda directory. Tesorflow is working from terminal but in R shows Error: Command failed (1)

Anybody can help me to how I can solve the problem? Should I uninstall anaconda and install Tensorflow using pip?

You have several options on what to do. Probably the cleanest one is to install a system-wide python (if not installed yet) and then create a virtual environment . This basically takes your system python binaries and moves them to its own compartment where everythign is isolated from the rest, incl. anaconda. Once you are inside an activated virtual environment you can install all the necessary Python appendages for TensorFlow. Once that is done, make sure you set up a correct environmental PATH for TensorFlow from where R can reach it:

Sys.setenv(TENSORFLOW_PYTHON="/path/to/virtualenv/python/binary")
devtools::install_github("rstudio/tensorflow")

Example of the path to where you installed the virtual environment project would be, I think, something like ~/minion/medvedi/venv_medvedi/bin/python .

This is no longer an issue, the documentation was updated too.

See here: https://github.com/rstudio/tensorflow/commit/4e1e11d6ba2fe7efe1a03356f96172dbf8db365e

With the help of Keras, we can install the TensorFlow package in R.

install_keras()
library(keras)
devtools::install_github("rstudio/keras")
install_tensorflow(package_url = "https://pypi.python.org/packages/b8/d6/af3d52dd52150ec4a6ceb7788bfeb2f62ecb6aa2d1172211c4db39b349a2/tensorflow-1.3.0rc0-cp27-cp27mu-manylinux1_x86_64.whl#md5=1cf77a2360ae2e38dd3578618eacc03b")
library(tensorflow)

Keras is a high-level neural network API for deep learning from TensorFlow Google.

Eventually I found the best and fast method to do it in R:

devtools::install_github("rstudio/keras")
library(keras)
install_keras(method = "conda")
install_keras(tensorflow = "gpu")
tensorflow::install_tensorflow()

my suggestion is to install anaconda and create an environment called "r-reticulate".

you can do it using anaconda navigator or

reticulate::conda_create(envname = "r-reticulate")

then to check that env detected by reticulate, use reticulate::conda_python() .it must return directory of python.exe for your env. after that you can install tensorflow by install_tensorflow() . [not working in my case]

so I install the tesnorflow from CMD. follow these steps:

  1. open the cmd :]

  2. activate the r-reticulate env using conda activate r-reticulate (you may need your directory to conda directory if you did not add conda to your PATH)

  3. use : conda install -c anaconda tensorflow

now in R, you can use TensorFlow. for installing Keras, you can use pip install Keras . [i tried install_keras() function after the installation of tensorflow, but it ruined my TensorFlow installation also]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM