Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R keras package Error: Python module tensorflow.contrib.keras.python.keras was not found

I have keras installed with devtools from GitHub in R and TensorFlow installed in Python.

However when I run an example Keras command like:

model <- keras_model_sequential() 

I get the following:

Error: Python module tensorflow.contrib.keras.python.keras was not found.

Detected Python configuration:

python:         C:\Python35\python.exe
libpython:      C:/Python35/python35.dll
pythonhome:     C:\Python35
version:        3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:\Python35\lib\site-packages\numpy
numpy_version:  1.13.0
tensorflow:     C:\Python35\lib\site-packages\tensorflow

python versions found: 
 C:\Python35\python.exe
 C:\Python27\\python.exe
 C:\Python35\\python.exe
 C:\Python36\\python.exe
like image 544
Hack-R Avatar asked Jun 18 '17 02:06

Hack-R


5 Answers

I had a similar problem. Restart rstudio, load keras and tensorflow libraries, and type use_condaenv("r-tensorflow"). That fixed it for me.

like image 68
Nihit Save Avatar answered Nov 01 '22 01:11

Nihit Save


First, you can install the R tensorflow package from here.

Then, you can just install the latest tensorflow version, using install_tensorflow function, as shown in this answer.

After that, just install and update R-keras library. It should use the last version of TensorFlow now, and this could potentially solve your problem. Also, make sure you install the tensorflow version that matches your Python version.

like image 5
Gabriel Barrionuevo-Rosales Avatar answered Nov 01 '22 03:11

Gabriel Barrionuevo-Rosales


I faced a similar problem and below steps helped to overcome the issue.

  1. Install TensorFlow and Keras from rstudio github.
  • devtools::install_github("rstudio/tensorflow")
  • devtools::install_github("rstudio/keras")
  1. Execute the below
  • tensorflow::install_tensorflow()
  • tensorflow::tf_config()
like image 4
Edayadulla M Avatar answered Nov 01 '22 01:11

Edayadulla M


I had a similar problem with a conda installation on a Mac (so using install_keras(method = 'conda', conda = '/opt/anaconda3/bin/conda'), which created a virtual environment called r-reticulate under ~/.conda/envs. Then when I tried to instantiate a model just like you do, I was getting an error 'Error: Python module tensorflow.python.keras was not found.'

For me what resolved it is after loading library(keras) execute use_condaenv("r-reticulate", required = TRUE) and then everything worked.

like image 2
Valeri Voev Avatar answered Nov 01 '22 03:11

Valeri Voev


I faced a similar problem. The issue was solved by updating the tensorflow module from 1.0.1 to 1.2.1

like image 1
itamar kanter Avatar answered Nov 01 '22 02:11

itamar kanter