keras not found after installation in R Studio

Hi guys, I installed keras package with the following command:

install.packages("keras")
library(keras)
install_keras()

However, it was not found even if I was prompted:
"Successfully installed keras-2.2.4 keras-applications-1.0.7 keras-preprocessing-1.0.9 tensorflow-hub-0.3.0

Installation complete." by R Studio.

I was wondering if someone could please help me with installing this package as it is really important for me to continue with my work in Artifical intelligence class.

I am relying on your expertise. Thank you guys soooo much!

Also, please see the error message attached.

library(keras)

model1<-keras_model_sequential() %>%

  • layer_dense(units=1, input_shape=c(5), activation="linear")
    Error: Python module keras was not found.

Detected Python configuration:

python: /Users/Anna/anaconda3/envs/r-reticulate/bin/python
libpython: /Users/Anna/anaconda3/envs/r-reticulate/lib/libpython3.7m.dylib
pythonhome: /Users/Anna/anaconda3/envs/r-reticulate:/Users/Anna/anaconda3/envs/r-reticulate
version: 3.7.2 (default, Dec 29 2018, 00:00:04) [Clang 4.0.1 (tags/RELEASE_401/final)]
numpy: /Users/Anna/anaconda3/envs/r-reticulate/lib/python3.7/site-packages/numpy
numpy_version: 1.16.2
keras: [NOT FOUND]

python versions found:
/Users/Anna/anaconda3/envs/r-reticulate/bin/python
/Users/Anna/anaconda3/envs/r-tensorflow/bin/python
/usr/bin/python
/usr/local/bin/python
/usr/local/bin/python3
/Users/Anna/anaconda3/bin/python

reticulate::py_discover_config("keras")
python: /Users/Anna/anaconda3/envs/r-reticulate/bin/python
libpython: /Users/Anna/anaconda3/envs/r-reticulate/lib/libpython3.7m.dylib
pythonhome: /Users/Anna/anaconda3/envs/r-reticulate:/Users/Anna/anaconda3/envs/r-reticulate
version: 3.7.2 (default, Dec 29 2018, 00:00:04) [Clang 4.0.1 (tags/RELEASE_401/final)]
numpy: /Users/Anna/anaconda3/envs/r-reticulate/lib/python3.7/site-packages/numpy
numpy_version: 1.16.2
keras: [NOT FOUND]

python versions found:
/Users/Anna/anaconda3/envs/r-reticulate/bin/python
/usr/bin/python
/usr/local/bin/python
/usr/local/bin/python3
/Users/Anna/anaconda3/bin/python
/Users/Anna/anaconda3/envs/r-tensorflow/bin/python

reticulate::py_discover_config("tensorflow")
python: /Users/Anna/anaconda3/envs/r-reticulate/bin/python
libpython: /Users/Anna/anaconda3/envs/r-reticulate/lib/libpython3.7m.dylib
pythonhome: /Users/Anna/anaconda3/envs/r-reticulate:/Users/Anna/anaconda3/envs/r-reticulate
version: 3.7.2 (default, Dec 29 2018, 00:00:04) [Clang 4.0.1 (tags/RELEASE_401/final)]
numpy: /Users/Anna/anaconda3/envs/r-reticulate/lib/python3.7/site-packages/numpy
numpy_version: 1.16.2
tensorflow: [NOT FOUND]

python versions found:
/Users/Anna/anaconda3/envs/r-reticulate/bin/python
/Users/Anna/anaconda3/envs/r-tensorflow/bin/python
/usr/bin/python
/usr/local/bin/python
/usr/local/bin/python3
/Users/Anna/anaconda3/bin/python

1 Like

Are you using a conda environment? Try with this

install_keras(method = "conda")
1 Like

I had a similar problem recently - for me it turned out that two versions of numpy were installed into the conda environment created by the keras library.

The process to discover my issue was to:

  1. Open a terminal
  2. Use command source activate r-tensorflow to start the conda environment that keras uses by default.
  3. Start python by running command python
  4. Run command import tensorflow. For me, this gave the error message about multiple numpy versions and explained how to fix (uninstalling numpy with pip uninstall numpy until it was totally gone (twice for me) and then reinstalling - I used pip install numpy and it worked, but don't know if that's the best way).

I had assumed there was something strange about my system that caused me to have this problem, but if the same thing happened to you, it might be worth reporting on the keras library github page.

1 Like

Could not find conda environment: r-tensorflow

You can list all discoverable environments with conda info --envs.

This is the error message I got. Can you please help? Thanks!

Hm, did you try running command conda info --envs? If so, what was the output?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.