Reputation: 1590
I'm trying to install deep learning package keras
on RStudio using this website. I installed keras
using
install.packages("keras")
library(keras)
install_keras()
but when I tried to open the MNIST
dataset
mnist <- dataset_mnist()
I keep getting the error
Error: ModuleNotFoundError: No module named 'absl'
I thought keras installed tensorflow but do I need to install tensorflow separately?
Upvotes: 4
Views: 7581
Reputation: 1
For me it was really like @pari said in the accepted answer but in addition I had to force the default Python version to downgrade (3.12 -> 3.9).
install.packages("keras")
install_keras(python_version = "3.9")
It is confusing that this keyword argument does not appear in the official doc but only in the tensorflow::install_tensorflow
doc
Upvotes: 0
Reputation: 216
I had the same problem, but mine was solved by enclosing keras
in double quotes.
install.packages("keras") ## worked for me,
install.packages(keras) ## never worked.
Upvotes: 2
Reputation: 23
try:
install.packages("devtools")
devtools::install_github("rstudio/keras")
library(keras)
mnist<-dataset_mnist()
Upvotes: 1
Reputation: 41
If you follow the TUT and still got error, try running py_config()
and check the python and libpython if it is pointing to an r-tensorflow environment. If not, best to try manually install keras in your manually set up conda environment.
#Open rstudio and run the following command
devtools::install_github("rstudio/keras")
#Don't close rstudio after running this, okay?
In summary, the link will teach you to install anaconda, create an environment and install necessary libraries. Just follow it. I named my environment as “r-tensorflow” because that is the name of the environment that the install_keras() in R will do :)
Open your rstudio (if you close it after following step 1) and type the following code
library(keras)
library(reticulate)
# in case you run into error run this : reticulate::py_discover_config("keras")
use_python("<yourpath>/Anaconda3/envs/r-tensorflow/Scripts/python.exe")
# change <yourpath> approriately
# write all the codes for building model in keras (or tensorflow) e.g. mnist<-dataset_mnist()
Important note on Step 3: If you still got the "not found module" after following step 3, you must start a new fresh R session and ensure to delete the workspace (.RData) because more likely your current script will still use the old python configuration though you used use_python
Upvotes: 4
Reputation: 808
I had the same problem and it is solved by installing the package in two steps:
install keras: install.packages("keras")
keras::install_keras()
There you go!
Upvotes: 5
Reputation: 1333
Please install "reticulate" library using command install.packages("reticulate")
and then load using library(reticulate)
then install absl using command
conda_install('r-tensorflow','absl-py')
Upvotes: 0