3

I am trying to use kerasR for deep learning in R. I am trying to reproduce the examples in the package. Trying the following code produces error:

library(kerasR)
mod <- Sequential()

The error is:

Error in Sequential() : attempt to apply non-function
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Leo
  • 31
  • 1
  • 2
  • The [onLoad](https://github.com/statsmaths/kerasR/blob/master/R/onLoad.R) function for that package tries to load the modules from python. It's really just an R wrapper for the python package. Do you have python installed and do you have both the "keras" and "numpy" python modules installed? – MrFlick Apr 07 '17 at 14:43
  • I have Anaconda python installed with numpy, theano and keras. – Leo Apr 08 '17 at 01:38
  • 1
    Does `reticulate::py_module_available("keras") ` return TRUE? – MrFlick Apr 08 '17 at 01:49
  • It returns FALSE, which probably means it cannot detect the keras in anaconda. – Leo Apr 08 '17 at 02:24
  • Do you have a virtual environment set up for your python or something? Maybe checkout the documentation for the `reticulate` package to see where it looks for python and installed packages. – MrFlick Apr 08 '17 at 02:26
  • I do not have a virtual environment. Does it have an issue with Python3? I will search the reticulate package documentation. – Leo Apr 08 '17 at 02:45

1 Answers1

2

I'd suggest to look at this issue in KerasR Github repo: https://github.com/statsmaths/kerasR/issues/1

Basically you should check where is located your version of python and then use reticulate::use_python("PATH_TO_PYTHON") to tell the system where to find Python.

Watch Out!
You can load just one Python interpreter per session and the use_python() function doesn't warn you if there already is a loaded interpreter.
Moreover if you run py_config() it automatically loads the first interpreter that he finds (which, in your case, seems to be the wrong one!), thus you'd better call reticulate::use_python("PATH_TO_PYTHON") before anything else.

NDonelli
  • 51
  • 6