Keras: `install_keras()` doesn't work within RStudio

Created on 26 Jan 2019  Â·  13Comments  Â·  Source: rstudio/keras

I have been trying to load keras module on a Windows machine in RStudio 1.2 and development (3.6.0)version of R and I can't seem to make it work.

Any solutions?

  • attempt-1
library(keras)
install_keras()
Creating r-tensorflow conda environment for TensorFlow installation...
Solving environment: ...working... failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/r/noarch/repodata.json.bz2>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.

SSLError(MaxRetryError('HTTPSConnectionPool(host=\'repo.anaconda.com\', port=443): Max retries exceeded with url: /pkgs/r/noarch/repodata.json.bz2 (Caused by SSLError("Can\'t connect to HTTPS URL because the SSL module is not available."))'))


Error: Error 1 occurred creating conda environment r-tensorflow
  • attempt-2 (fails for the same reason)
library(keras)
use_condaenv("r-tensorflow")
Sys.setenv(KERAS_BACKEND="theano") 
install_keras()
#> Creating r-tensorflow conda environment for TensorFlow installation...
#> Error: Error 1 occurred creating conda environment r-tensorflow
  • Setup
    Checking setup (details based on recommendations made in similar issues threads in this repo)
library(reticulate)

reticulate::py_available(initialize = TRUE)
#> [1] TRUE

reticulate::py_versions_windows()
#>         type hive                                          install_path
#> 1 PythonCore  HCU C:\\Users\\inp099\\AppData\\Local\\CONTIN~1\\ANACON~1
#> 2   Anaconda  HCU C:\\Users\\inp099\\AppData\\Local\\CONTIN~1\\ANACON~1
#>                                                     executable_path
#> 1 C:\\Users\\inp099\\AppData\\Local\\CONTIN~1\\ANACON~1\\python.exe
#> 2 C:\\Users\\inp099\\AppData\\Local\\CONTIN~1\\ANACON~1\\python.exe
#>   version arch
#> 1     3.7  x64
#> 2     3.7  x64

reticulate::py_config()
#> python:         C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1\python.exe
#> libpython:      C:/Users/inp099/AppData/Local/CONTIN~1/ANACON~1/python37.dll
#> pythonhome:     C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1
#> version:        3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)]
#> Architecture:   64bit
#> numpy:           [NOT FOUND]
#> 
#> python versions found: 
#>  C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1\python.exe
#>  C:\Users\inp099\AppData\Local\Continuum\anaconda3\python.exe

reticulate::py_discover_config("keras")
#> python:         C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1\python.exe
#> libpython:      C:/Users/inp099/AppData/Local/CONTIN~1/ANACON~1/python37.dll
#> pythonhome:     C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1
#> version:        3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)]
#> Architecture:   64bit
#> numpy:          C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1\lib\site-packages\numpy
#> numpy_version:  1.15.4
#> keras:          [NOT FOUND]
#> 
#> python versions found: 
#>  C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1\python.exe
#>  C:\Users\inp099\AppData\Local\Continuum\anaconda3\python.exe

reticulate::py_discover_config("tensorflow")
#> python:         C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1\python.exe
#> libpython:      C:/Users/inp099/AppData/Local/CONTIN~1/ANACON~1/python37.dll
#> pythonhome:     C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1
#> version:        3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)]
#> Architecture:   64bit
#> numpy:          C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1\lib\site-packages\numpy
#> numpy_version:  1.15.4
#> tensorflow:     [NOT FOUND]
#> 
#> python versions found: 
#>  C:\Users\inp099\AppData\Local\CONTIN~1\ANACON~1\python.exe
#>  C:\Users\inp099\AppData\Local\Continuum\anaconda3\python.exe

Created on 2019-01-26 by the reprex package (v0.2.1)

  • Session information

Session info

devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2018-11-30 r75724)
#>  os       Windows 10 x64                                    
#>  system   x86_64, mingw32                                   
#>  ui       RTerm                                             
#>  language (EN)                                              
#>  collate  English_United States.1252                        
#>  ctype    English_United States.1252                        
#>  tz       America/New_York                                  
#>  date     2019-01-26                                        
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib source                         
#>  assertthat    0.2.0      2017-04-11 [1] CRAN (R 3.5.1)                 
#>  backports     1.1.3      2018-12-14 [1] CRAN (R 3.6.0)                 
#>  callr         3.1.1      2018-12-21 [1] CRAN (R 3.6.0)                 
#>  cli           1.0.1.9000 2019-01-20 [1] Github (r-lib/cli@94e2fc5)     
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.5.1)                 
#>  desc          1.2.0      2019-01-21 [1] Github (r-lib/desc@42b9578)    
#>  devtools      2.0.1.9000 2019-01-23 [1] Github (r-lib/devtools@3c368ad)
#>  digest        0.6.18     2018-10-10 [1] CRAN (R 3.5.1)                 
#>  evaluate      0.12       2018-10-09 [1] CRAN (R 3.5.1)                 
#>  fs            1.2.6      2018-08-23 [1] CRAN (R 3.5.1)                 
#>  glue          1.3.0      2018-07-17 [1] CRAN (R 3.5.1)                 
#>  highr         0.7        2018-06-09 [1] CRAN (R 3.5.1)                 
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.5.1)                 
#>  jsonlite      1.6        2018-12-07 [1] CRAN (R 3.6.0)                 
#>  knitr         1.21       2018-12-10 [1] CRAN (R 3.6.0)                 
#>  lattice       0.20-38    2018-11-04 [2] CRAN (R 3.6.0)                 
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.5.1)                 
#>  Matrix        1.2-15     2018-11-01 [1] CRAN (R 3.5.1)                 
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.5.1)                 
#>  pkgbuild      1.0.2      2018-10-16 [1] CRAN (R 3.5.1)                 
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)                 
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.5.1)                 
#>  processx      3.2.1      2018-12-05 [1] CRAN (R 3.6.0)                 
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                 
#>  R6            2.3.0      2018-10-04 [1] CRAN (R 3.5.1)                 
#>  Rcpp          1.0.0      2018-11-07 [1] CRAN (R 3.6.0)                 
#>  remotes       2.0.2      2018-10-30 [1] CRAN (R 3.6.0)                 
#>  reticulate  * 1.10       2018-08-05 [1] CRAN (R 3.5.2)                 
#>  rlang         0.3.1      2019-01-08 [1] CRAN (R 3.6.0)                 
#>  rmarkdown     1.11       2018-12-08 [1] CRAN (R 3.6.0)                 
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.5.1)                 
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                 
#>  stringi       1.2.4      2018-07-20 [1] CRAN (R 3.6.0)                 
#>  stringr       1.3.1      2018-05-10 [1] CRAN (R 3.5.1)                 
#>  testthat      2.0.1      2018-10-13 [1] CRAN (R 3.5.1)                 
#>  usethis       1.4.0.9000 2019-01-24 [1] Github (r-lib/usethis@3339fe9) 
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.5.1)                 
#>  xfun          0.4        2018-10-23 [1] CRAN (R 3.6.0)                 
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.5.1)                 
#> 
#> [1] C:/Users/inp099/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-devel/library

Most helpful comment

For those who are facing a similar issue, here is how this can be solved. It's not easy to install keras from your installed version of RStudio.

Instead, install anaconda (https://www.anaconda.com/) and install a new version of RStudio in the conda environment. You should then be able to launch this new RStudio.

image

In this RStudio, you can do-

library(keras)
install_keras()

Voila!! It should work.

All 13 comments

I am facing the same problem. Could any one help please.

@Bijurikaaa @IndrajeetPatil I had the same issue on two macs. Then I installed R studio on the platform Anaconda, installed keras package and r-tensorflow. Everything works well now, you can try it.

Sounds good. Shall try this. Thanks much.

Bijurika Baidya
Phone (9051137154)

On Tue 29 Jan, 2019, 08:22 sjwscjj <[email protected] wrote:

@Bijurikaaa https://github.com/Bijurikaaa @IndrajeetPatil
https://github.com/IndrajeetPatil I had the same issue on two macs.
Then I installed R studio on the platform Anaconda, installed keras package
and r-tensorflow. Everything works well now, you can try it.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rstudio/keras/issues/649#issuecomment-458387699, or mute
the thread
https://github.com/notifications/unsubscribe-auth/As7gwC2yWpBxziKjrMXVCew2oC-Ocz8tks5vH7eIgaJpZM4aUNfy
.

For those who are facing a similar issue, here is how this can be solved. It's not easy to install keras from your installed version of RStudio.

Instead, install anaconda (https://www.anaconda.com/) and install a new version of RStudio in the conda environment. You should then be able to launch this new RStudio.

image

In this RStudio, you can do-

library(keras)
install_keras()

Voila!! It should work.

Hello to everybody on this thread,

if you still have problems using install_tensorflow() from RStudio, please try again now.

First install tensorflow directly from GitHub, as in

devtools::install_github("rstudio/tensorflow")
devtools::install_github("rstudio/keras")

Then do

tensorflow::install_tensorflow()
tensorflow::tf_config()

which should give you version 1.12.

We have been installing TF 1.10 until yesterday because of a bug in that will only be fixed in TF 1.13 (which should be out anytime but unfortunately isn't yet). Now with people having installation problems due to incompatibilities with numpy as installed by conda, we decided to switch to TF 1.12 now and as soon as TF 1.13 is actually available, we'll install that by default.

Thanks for reporting the problem!

If you still run into problems installing, please open another issue and describe the problem, indicating the output of

reticulate::py_discover_config()
reticulate::use_condaenv("r-tensorflow")
reticulate::py_config()

Thanks!

reticulate::py_discover_config()
python: C:\Users\ajitb\ANACON~1\python.exe
libpython: C:/Users/ajitb/ANACON~1/python36.dll
pythonhome: C:\Users\ajitb\ANACON~1
version: 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
Architecture: 64bit
numpy: C:\Users\ajitb\ANACON~1\lib\site-packagesnumpy
numpy_version: 1.14.3

python versions found:
C:\Users\ajitb\ANACON~1\python.exe
C:\Users\ajitb\AppData\Local\Programs\Python\PYTHON~1\python.exe
C:\Users\ajitb\Anaconda3\python.exe
C:\Users\ajitb\Anaconda3\envs\r-tensorflow\python.exe

reticulate::use_condaenv("r-tensorflow")
reticulate::py_config()
python: C:\Users\ajitb\ANACON~1\python.exe
libpython: C:/Users/ajitb/ANACON~1/python36.dll
pythonhome: C:\Users\ajitb\ANACON~1
version: 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
Architecture: 64bit
numpy: C:\Users\ajitb\ANACON~1\lib\site-packagesnumpy
numpy_version: 1.14.3
tensorflow: [NOT FOUND]

python versions found:
C:\Users\ajitb\Anaconda3\envs\r-tensorflow\python.exe
C:\Users\ajitb\ANACON~1\python.exe
C:\Users\ajitb\AppData\Local\Programs\Python\PYTHON~1\python.exe
C:\Users\ajitb\Anaconda3\python.exe

Hello to everybody on this thread,

if you still have problems using install_tensorflow() from RStudio, please try again now.

First install tensorflow directly from GitHub, as in

devtools::install_github("rstudio/tensorflow")
devtools::install_github("rstudio/keras")

Then do

tensorflow::install_tensorflow()
tensorflow::tf_config()

which should give you version 1.12.

We have been installing TF 1.10 until yesterday because of a bug in that will only be fixed in TF 1.13 (which should be out anytime but unfortunately isn't yet). Now with people having installation problems due to incompatibilities with numpy as installed by conda, we decided to switch to TF 1.12 now and as soon as TF 1.13 is actually available, we'll install that by default.

Thanks for reporting the problem!

If you still run into problems installing, please open another issue and describe the problem, indicating the output of

reticulate::py_discover_config()
reticulate::use_condaenv("r-tensorflow")
reticulate::py_config()

Thanks!

Thank a lot!!!

In case this helps someone:

I was having the same problems as OP, however, I got tensorflow-gpu and keras-gpu running by going to /Documents/.conda/envs and deleting the folder "r-reticulate". Not sure why/how it was created, but that seemed to be the cause of the messed up environment.

Now go back into R, then reinstall reticulate and everything should be working!

This is the only Keras Rstudio installation method that has ever worked for me:
https://irudnyts.github.io/custom-set-up-of-keras-and-tensorflow-for-r-and-python/

works seamlessly

I was having issues with this as well due to having some gnarly Python installations on the VM I'm working from (partly my fault; partly my organization's fault). What finally got it to work as that I had a separate installation of Anaconda just for my user, so I went in and modified my PATH environment variable to look there before any other Python environments. The keras::install_keras() worked perfectly after that.

For those who are facing a similar issue, here is how this can be solved. It's not easy to install keras from your installed version of RStudio.

Instead, install anaconda (https://www.anaconda.com/) and install a new version of RStudio in the conda environment. You should then be able to launch this new RStudio.

image

In this RStudio, you can do-

library(keras)
install_keras()

Voila!! It should work.

Hi,
I have tried this method, it worked till I compiled the network then I got a fatal error.
tried it multiples times and kept getting the same error.

How can I solve it?

In case this helps someone:

I was having the same problems as OP, however, I got tensorflow-gpu and keras-gpu running by going to /Documents/.conda/envs and deleting the folder "r-reticulate". Not sure why/how it was created, but that seemed to be the cause of the messed up environment.

Now go back into R, then reinstall reticulate and everything should be working!

thanks it works for me

This is the only Keras Rstudio installation method that has ever worked for me:
https://irudnyts.github.io/custom-set-up-of-keras-and-tensorflow-for-r-and-python/

works seamlessly

This worked for me after so many other things failed!
Thank you!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fderyckel picture fderyckel  Â·  4Comments

gundalav picture gundalav  Â·  3Comments

leonjessen picture leonjessen  Â·  4Comments

mattwarkentin picture mattwarkentin  Â·  3Comments

aliarsalankazmi picture aliarsalankazmi  Â·  4Comments