Keras: Error 1 occurred creating conda environment r-tensorflow

Created on 31 Dec 2018  路  17Comments  路  Source: rstudio/keras

Just tried to install keras but got a problem. Just to narrow it down as much as possible, these were my steps:

  1. installation of R 3.5.2
  2. installation of RStudio 1.1.463
  3. installation of Python 3.6 (only for the current user, 64bit)
  4. installation of Anaconda 2018.12 (only for the current user, 64 bit)
  5. installation of keras in R via RStudio
install.packages("keras")
library(keras)
install_keras(method = "conda")

After that, I got the first error.

> library(keras)
> install_keras(method = "conda")
Creating r-tensorflow conda environment for TensorFlow installation...
Solving environment: ...working... failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/pro/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/pro/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
>

I was able to solve this one by following another advice: [https://stackoverflow.com/questions/46803208/install-keras-in-rstudio-fails-with-http-connection-error/47027837]

However, now I get a new one and have no idea how to solve it.

> library(keras)
> install_keras(method = "conda")
Creating r-tensorflow conda environment for TensorFlow installation...
Solving environment: ...working... failed

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "D:\Programme\Anaconda3\lib\site-packages\requests\adapters.py", line 412, in send
        conn = self.get_connection(request.url, proxies)
      File "D:\Programme\Anaconda3\lib\site-packages\requests\adapters.py", line 305, in get_connection
        proxy_url = parse_url(proxy)
      File "D:\Programme\Anaconda3\lib\site-packages\urllib3\util\url.py", line 199, in parse_url
        raise LocationParseError(url)
    urllib3.exceptions.LocationParseError: Failed to parse: proxy.server.com:port

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "D:\Programme\Anaconda3\lib\site-packages\conda\exceptions.py", line 819, in __call__
        return func(*args, **kwargs)
      File "D:\Programme\Anaconda3\lib\site-packages\conda\cli\main.py", line 78, in _main
        exit_code = do_call(args, p)
      File "D:\Programme\Anaconda3\lib\site-packages\conda\cli\conda_argparse.py", line 77, in do_call
        exit_code = getattr(module, func_name)(args, parser)
      File "D:\Programme\Anaconda3\lib\site-packages\conda\cli\main_create.py", line 11, in execute
        install(args, parser, 'create')
      File "D:\Programme\Anaconda3\lib\site-packages\conda\cli\install.py", line 235, in install
        force_reinstall=context.force,
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\solve.py", line 518, in solve_for_transaction
        force_remove, force_reinstall)
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\solve.py", line 451, in solve_for_diff
        final_precs = self.solve_final_state(deps_modifier, prune, ignore_pinned, force_remove)
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\solve.py", line 180, in solve_final_state
        index, r = self._prepare(prepared_specs)
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\solve.py", line 592, in _prepare
        self.subdirs, prepared_specs)
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\index.py", line 215, in get_reduced_index
        new_records = query_all(spec)
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\index.py", line 184, in query_all
        return tuple(concat(future.result() for future in as_completed(futures)))
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 95, in query
        self.load()
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 149, in load
        _internal_state = self._load()
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 227, in _load
        mod_etag_headers.get('_mod'))
      File "D:\Programme\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 437, in fetch_repodata_remote_request
        timeout=timeout)
      File "D:\Programme\Anaconda3\lib\site-packages\requests\sessions.py", line 546, in get
        return self.request('GET', url, **kwargs)
      File "D:\Programme\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
        resp = self.send(prep, **send_kwargs)
      File "D:\Programme\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
        r = adapter.send(request, **kwargs)
      File "D:\Programme\Anaconda3\lib\site-packages\requests\adapters.py", line 414, in send
        raise InvalidURL(e, request=request)
    requests.exceptions.InvalidURL: Failed to parse: proxy.server.com:port

`$ D:\Programme\Anaconda3\Scripts\conda create --yes --name r-tensorflow python=3.6`

  environment variables:
                 CIO_TEST=<not set>
               CONDA_ROOT=D:\Programme\Anaconda3
                 HOMEPATH=\Users\admin
              HTTPS_PROXY=<set>
               HTTP_PROXY=<set>
                     PATH=D:\Programme\R-3.5.2\bin\x64;D:\Programme\Python37\Scripts\;D:\Program
                          me\Python37\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C
                          :\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH
                          \;C:\Program Files\Microsoft VS Code\bin;D:\Programme\Python36\Scripts
                          \;D:\Programme\Python36\;C:\Users\admin\AppData\Local\Programs\Python\
                          Launcher\;D:\Programme\Python37\Scripts\;D:\Programme\Python37\;C:\Use
                          rs\admin\AppData\Local\Microsoft\WindowsApps;C:\Users\admin\AppData\Lo
                          cal\rodeo\app-2.5.2\bin
             PSMODULEPATH=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\Windows
                          PowerShell\v1.0\Modules
       REQUESTS_CA_BUNDLE=<not set>
   RMARKDOWN_MATHJAX_PATH=D:/Programme/RStudio/resources/mathjax-26
        RS_RPOSTBACK_PATH=D:/Programme/RStudio/bin/rpostback
            SSL_CERT_FILE=<not set>

     active environment : None
       user config file : C:\Users\admin\Documents\.condarc
 populated config files : 
          conda version : 4.5.12
    conda-build version : 3.17.6
         python version : 3.7.1.final.0
       base environment : D:\Programme\Anaconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/win-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/win-64
                          https://repo.anaconda.com/pkgs/pro/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : D:\Programme\Anaconda3\pkgs
                          C:\Users\admin\AppData\Local\conda\conda\pkgs
       envs directories : D:\Programme\Anaconda3\envs
                          C:\Users\admin\AppData\Local\conda\conda\envs
                          C:\Users\admin\Documents\.conda\envs
               platform : win-64
             user-agent : conda/4.5.12 requests/2.21.0 CPython/3.7.1 Windows/10 Windows/10.0.17134
          administrator : False
             netrc file : None
           offline mode : False


An unexpected error has occurred. Conda has prepared the above report.
Upload did not complete.Error: Error 1 occurred creating conda environment r-tensorflow
> 

Below is my session info (OS: Windows 10, 64bit).

> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] keras_2.2.4

loaded via a namespace (and not attached):
 [1] compiler_3.5.2  Matrix_1.2-15   magrittr_1.5    R6_2.3.0        generics_0.0.2  tools_3.5.2     whisker_0.3-2  
 [8] base64enc_0.1-3 Rcpp_1.0.0      reticulate_1.10 tensorflow_1.10 grid_3.5.2      zeallot_0.1.0   jsonlite_1.6   
[15] tfruns_1.4      lattice_0.20-38
> 

Any ideas?

Most helpful comment

Hi everyone, after a lot of trial and error, I was finally able to get it to work.

To isolate it as far as possible, I installed windows 10 everytime anew.

Only thing that did work (executed in the following order):
1.) installation of R 3.5.2 (independent from directory (standard or any other))
2.) installation of RStudio (independent from directory)
3.) RStudio -> Tools -> Global Options -> Packages -> Disable both "Use secure download method for HTTP" and "Use Internet Explorer library/proxy for HTTP"
4.) installation of Miniconda3 (-> has to be the standard directory!) Version 4.5.11 (it did not work with the newest version)
5.) Use RStudio ->
install.packages("tensorflow")
install.packages("keras")
library("keras")
install_keras()

This worked for me and I am now able to use keras in R. After that I installed Anaconda (newest version) and used keras with python in an environment for python 3.6 (wich worked).

However, I only tried everything with the CPU version (no idea if it would work for the GPU version).

What did not work (resulted in a HTTP Connection Error):

  • newest Anaconda (independent whether installed in the standard directory or not)
  • newest Miniconda (independent whether installed in the standard directory or not)
  • any other solution that tried to solve the HTTP Connection error or the SSL error

Hope this helps for other people as well.

All 17 comments

Following that SO advice, did you fill in your _actual_ proxy's settings in .Renviron?

Asking b/c

requests.exceptions.InvalidURL: Failed to parse: proxy.server.com:port

I have the similar issue with:

  • Windows 10 Pro
  • R 3.5.2
  • Miniconda 4.5.12
  • Python 3.7.1
> 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/free/win-64/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/free/win-64/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

https://stackoverflow.com/questions/46803208/install-keras-in-rstudio-fails-with-http-connection-error/47027837

Did not help me to solve the issue.

Do you have any idea what is root cause of this problem.
It seems SSL library is not accessible.
But

conda update --all

does not give me any error.
There is no proxy server setting.

Thanks.

@skeydan is there anyway to trace and identify what the problem is?
Thanks.

I had the similar issue. followed the instruction from following and it went away -

https://medium.com/@pushkarmandot/installing-tensorflow-theano-and-keras-in-spyder-84de7eb0f0df

Hope that helps!

Hi @mg64ve
I've never experienced this and am not on Windows, but in the SO answer it says

First step:

Rstudio --> Tools --> Global Options --> packages --> uncheck both "Use secure download method for HTTP" and "Use Internet Explorer librayr/proxy for HTTP"

So I'm wondering - from your error message it seems it's still trying to use https?

Thanks @skeydan !
However the comment from @dipeshj was more useful.
I basically ran conda, activated the environment and from there I ran Rgui.exe.
Then I was able to successfully install keras package and tensorflow-gpu.
Unfortunately I could not understand why this happened.
It seems an interaction between keras and conda is not perfectly working or it might be due to some environment variable.
Thank you any way!

Great you got it working, anyway! For others who run into the same problem, do you know if just activating the conda env would have been sufficient (meaning, you could then have installed from RStudio) - or was it necessary to use Rgui.exe instead?

Hi everyone, after a lot of trial and error, I was finally able to get it to work.

To isolate it as far as possible, I installed windows 10 everytime anew.

Only thing that did work (executed in the following order):
1.) installation of R 3.5.2 (independent from directory (standard or any other))
2.) installation of RStudio (independent from directory)
3.) RStudio -> Tools -> Global Options -> Packages -> Disable both "Use secure download method for HTTP" and "Use Internet Explorer library/proxy for HTTP"
4.) installation of Miniconda3 (-> has to be the standard directory!) Version 4.5.11 (it did not work with the newest version)
5.) Use RStudio ->
install.packages("tensorflow")
install.packages("keras")
library("keras")
install_keras()

This worked for me and I am now able to use keras in R. After that I installed Anaconda (newest version) and used keras with python in an environment for python 3.6 (wich worked).

However, I only tried everything with the CPU version (no idea if it would work for the GPU version).

What did not work (resulted in a HTTP Connection Error):

  • newest Anaconda (independent whether installed in the standard directory or not)
  • newest Miniconda (independent whether installed in the standard directory or not)
  • any other solution that tried to solve the HTTP Connection error or the SSL error

Hope this helps for other people as well.

Great you got it working, anyway! For others who run into the same problem, do you know if just activating the conda env would have been sufficient (meaning, you could then have installed from RStudio) - or was it necessary to use Rgui.exe instead?

@skeydan I would like to help others, but I am not using Rstudio at the moment, I am only using R 3.5.2 and I just ran Rgui.exe and it worked for me. Unfortunately I can not give you more information.

Thanks all for documenting what worked/did not work for you!
I'm closing this then.

Following that SO advice, did you fill in your _actual_ proxy's settings in .Renviron?

Asking b/c

requests.exceptions.InvalidURL: Failed to parse: proxy.server.com:port

What to do if I don't have a proxy? How do I find my actual proxy settings?

@mg64ve Thanks. I had the same problem, i.e. install_keras(method="conda") failed due to SSL error. Here are some clarifications as the steps you took were bit unclear.
In Anaconda prompt I executed:

  1. conda create -n py37 python=3.7 anaconda
  2. conda activate
  3. Browse to R location
  4. (py37) C:\Program Files\R\R-3.5.2\bin>R.exe
  5. finally install_keras(method="conda")

Of course the management still did not work from rstudio and to run tensorflow::install_tensorflow() I had to run R from the conda enviroment. The need run that command was caused by inability to execute the example from https://keras.rstudio.com/index.html

> mnist <- dataset_mnist() Error: Keras loaded from tensorflow v1.4, however version 1.9 is required. Please update with tensorflow::install_tensorflow().

Unfortunatly, in the I got stuck with

> model %>% 
+   layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>% 
+   layer_dropout(rate = 0.4) %>% 
+   layer_dense(units = 128, activation = 'relu') %>%
+   layer_dropout(rate = 0.3) %>%
+   layer_dense(units = 10, activation = 'softmax')

Resulted errors from Python

`Error in py_call_impl(callable, dots$args, dots$keywords) : 
  AttributeError: 'Sequential' object has no attribute 'get_shape' 

13. | stop(structure(list(message = "AttributeError: 'Sequential' object has no attribute 'get_shape'",      call = py_call_impl(callable, dots$args, dots$keywords),      cppstack = structure(list(file = "", line = -1L, stack = "C++ stack not available on this system"), class = "Rcpp_stack_trace")), class = c("Rcpp::exception",  "C++Error", "error", "condition")))
-- | --`

`

Following that SO advice, did you fill in your _actual_ proxy's settings in .Renviron?
Asking b/c

requests.exceptions.InvalidURL: Failed to parse: proxy.server.com:port

What to do if I don't have a proxy? How do I find my actual proxy settings?

I don't have proxy either

@mg64ve Thanks. I had the same problem, i.e. install_keras(method="conda") failed due to SSL error. Here are some clarifications as the steps you took were bit unclear.
In Anaconda prompt I executed:

  1. conda create -n py37 python=3.7 anaconda
  2. conda activate
  3. Browse to R location
  4. (py37) C:\Program Files\R\R-3.5.2\bin>R.exe
  5. finally install_keras(method="conda")

Of course the management still did not work from rstudio and to run tensorflow::install_tensorflow() I had to run R from the conda enviroment. The need run that command was caused by inability to execute the example from https://keras.rstudio.com/index.html

> mnist <- dataset_mnist() Error: Keras loaded from tensorflow v1.4, however version 1.9 is required. Please update with tensorflow::install_tensorflow().

Unfortunatly, in the I got stuck with

> model %>% 
+   layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>% 
+   layer_dropout(rate = 0.4) %>% 
+   layer_dense(units = 128, activation = 'relu') %>%
+   layer_dropout(rate = 0.3) %>%
+   layer_dense(units = 10, activation = 'softmax')

Resulted errors from Python

`Error in py_call_impl(callable, dots$args, dots$keywords) : 
  AttributeError: 'Sequential' object has no attribute 'get_shape' 

13. | stop(structure(list(message = "AttributeError: 'Sequential' object has no attribute 'get_shape'",      call = py_call_impl(callable, dots$args, dots$keywords),      cppstack = structure(list(file = "", line = -1L, stack = "C++ stack not available on this system"), class = "Rcpp_stack_trace")), class = c("Rcpp::exception",  "C++Error", "error", "condition")))
-- | --`

`

@mmantyla honestly I don't understand what the problem is.
Maybe @skeydan may help you.

same

Hi everyone, after a lot of trial and error, I was finally able to get it to work.

To isolate it as far as possible, I installed windows 10 everytime anew.

Only thing that did work (executed in the following order):
1.) installation of R 3.5.2 (independent from directory (standard or any other))
2.) installation of RStudio (independent from directory)
3.) RStudio -> Tools -> Global Options -> Packages -> Disable both "Use secure download method for HTTP" and "Use Internet Explorer library/proxy for HTTP"
4.) installation of Miniconda3 (-> has to be the standard directory!) Version 4.5.11 (it did not work with the newest version)
5.) Use RStudio ->
install.packages("tensorflow")
install.packages("keras")
library("keras")
install_keras()

This worked for me and I am now able to use keras in R. After that I installed Anaconda (newest version) and used keras with python in an environment for python 3.6 (wich worked).

However, I only tried everything with the CPU version (no idea if it would work for the GPU version).

What did not work (resulted in a HTTP Connection Error):

  • newest Anaconda (independent whether installed in the standard directory or not)
  • newest Miniconda (independent whether installed in the standard directory or not)
  • any other solution that tried to solve the HTTP Connection error or the SSL error

Hope this helps for other people as well.

I even tried the above steps but still I am unable to install keras & tensorflow in R. Please someone help me on this.

Hi everybody,

Just would like to say that with thanks to @mg64ve I was able to get tensorflow etc installed.

You can go to the link provided by @dipeshj to install keras, theano and tensorflow via the authors recommended method.

Then within Anaconda, install the R gui and load it up in the environment which has the packages. From within this R studio gui (within Anaconda) just install_keras() and away you go :)

Many thanks
Michael

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fderyckel picture fderyckel  路  4Comments

aliarsalankazmi picture aliarsalankazmi  路  4Comments

faltinl picture faltinl  路  6Comments

systats picture systats  路  4Comments

gundalav picture gundalav  路  3Comments