Error: ModuleNotFoundError: No module named 'keras' when using keras in R

Viewed 449

I have a problem running Keras in R. When running mnist <- dataset_mnist() I get the error Error: ModuleNotFoundError: No module named 'keras'

I have installed the most recent version of Anaconda, I am running R version 3.5.1 in RStudio 1.1.463. In R I have run

library("keras")
install_keras()

and this succeeds.

When trying to run mnist <- dataset_mnist() I initially got the following error message:

ImportError: No module named keras
Use the install_keras() function to install the core Keras library
Error: Error loading Python module keras

When running

library(reticulate)
py_config()

I got the following output:

python:         /usr/bin/python
libpython:      /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome:     /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version:        2.7.10 (default, Oct  6 2017, 22:29:07)  [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
numpy:          /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
numpy_version:  1.8.0
keras:          [NOT FOUND]

After looking at suggested solutions to other topics, I added this line to my .Rprofile

Sys.setenv(RETICULATE_PYTHON = "/anaconda3/envs/r-tensorflow/bin")

However when I run mnist <- dataset_mnist() now I get the following error:

Error: Python module keras was not found.

Detected Python configuration:

python:         /anaconda3/envs/r-tensorflow/bin/python
libpython:      /anaconda3/envs/r-tensorflow/lib/libpython3.6m.dylib
pythonhome:     /anaconda3/envs/r-tensorflow:/anaconda3/envs/r-tensorflow
version:        3.6.7 | packaged by conda-forge | (default, Nov 20 2018, 18:37:09)  [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
numpy:           [NOT FOUND]
keras:          /anaconda3/envs/r-tensorflow/lib/python3.6/site-packages/keras

NOTE:

Does anyone know what I can do to solve this?

0 Answers
Related