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
I had a similar problem. Restart rstudio, load keras and tensorflow libraries, and type use_condaenv("r-tensorflow")
. That fixed it for me.
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.
I faced a similar problem and below steps helped to overcome the issue.
- Install TensorFlow and Keras from rstudio github.
- devtools::install_github("rstudio/tensorflow")
- devtools::install_github("rstudio/keras")
- Execute the below
- tensorflow::install_tensorflow()
- tensorflow::tf_config()
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.
I faced a similar problem. The issue was solved by updating the tensorflow module from 1.0.1 to 1.2.1