Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation Issue #1491

Open
alex-stanoyevitch opened this issue Feb 26, 2025 · 24 comments
Open

Installation Issue #1491

alex-stanoyevitch opened this issue Feb 26, 2025 · 24 comments

Comments

@alex-stanoyevitch
Copy link

This is my first time putting up an issue in GitHub, so I apologize in advance in case I may be doing something improperly in this submission.

I've been reading the 2nd edition of Chollet's book for a while now and REALLY hope to start using keras + tensorflow.
I have done following the installation instructions in Chap 3 for my PC:

  1. First installed Python, Git, and Rtools.
  2. Then I ran the following codes provided kindly to me by one of the book's authors (Tomasz K)
    install.packages("keras3")
    reticulate::install_python("3.11")
    keras3::install_keras()

When I paste (in order) all of the RCode snippets from Chap 2 to build the first network, all seems to work fine till I run the snippet:

model <- keras_model_sequential(list(
layer_dense(units = 512, activation = "relu"),
layer_dense(units = 10, activation = "softmax")
))

I get this error message:
'''Error in keras_model_sequential(list(layer_dense(units = 512, activation = "relu"), :
layers must be passed in as a named argument.'''

I'd very much appreciate anyone's help or advice on this.

My background: I am a professor in math and statistics and have been teaching machine learning every year for 8 years and have been using R for 13 years. I've never used Python nor needed to install it till I installed keras3. I am planning a new course in deep learning, but I need to work out such bugs and issues so as to avoid my students running into them. I need a powerful software but also a stable working environment.
My email address is [email protected] in case you need or would prefer to contact me directly on this issue.

@t-kalinowski
Copy link
Member

t-kalinowski commented Feb 28, 2025

Hi, thanks for reporting.

This error occurs if you are using keras instead of keras3.

Can you please try the development version of keras3 and let me know if this works for you?

pak::pak("rstudio/keras3")
print(keras3::op_convert_to_tensor("Hello World!"))
print(reticulate::py_config())

@alex-stanoyevitch
Copy link
Author

Thank you Tomasz, I ran these three commands in RStudio, it gave the following output:

pak::pak("rstudio/keras3")
'''! Using bundled GitHub PAT. Please add your own PAT using gitcreds::gitcreds_set().
✔ Updated metadata database: 5.67 MB in 15 files.
✔ Updating metadata database ... done

→ Will update 2 packages.
→ Will download 1 CRAN package (2.26 MB).
→ Will download 1 package with unknown size.

  • keras3 1.2.0 → 1.3.0 [bld][cmp][dl] (GitHub: e357997)
  • reticulate 1.39.0 → 1.41.0 [dl] (2.26 MB)

! keras3 and reticulate are loaded in the current R session, you probably need to restart R after the installation.

? Do you want to continue (Y/n) print(keras3::op_convert_to_tensor("Hello World!"))
Error: Aborted.

y
[1] -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0'''

I restarted RStudio and tried running again the same code from Chap 2 of the Chollet book, but when I got to the same snippet in my original post:

model <- keras_model_sequential(list(
layer_dense(units = 512, activation = "relu"),
layer_dense(units = 10, activation = "softmax")
))

But I am still getting the same error.

Do you have anything else that I can try?

@alex-stanoyevitch
Copy link
Author

Added information to last post:
I checked the list of installed packages in RStudio; keras3 is there but not keras.

@t-kalinowski
Copy link
Member

What is the output of py_config()?

@alex-stanoyevitch
Copy link
Author

py_config()
'''Error in py_config() : could not find function "py_config"'''

@t-kalinowski
Copy link
Member

reticulate::py_config()

@alex-stanoyevitch
Copy link
Author

reticulate::py_config()
'''python: C:/Users/Alex/Documents/.virtualenvs/r-reticulate/Scripts/python.exe
libpython: C:/Users/Alex/AppData/Local/Programs/Python/Python313/python313.dll
pythonhome: C:/Users/Alex/Documents/.virtualenvs/r-reticulate
version: 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Users/Alex/Documents/.virtualenvs/r-reticulate/Lib/site-packages/numpy
numpy_version: 2.2.0'''

@t-kalinowski
Copy link
Member

t-kalinowski commented Mar 4, 2025

Can you please run:

reticulate::virtualenv_remove("r-reticulate")

Alternatively, you can also use the unexported rm_all_reticulate_state to completely revert to a clean slate:

reticulate:::rm_all_reticulate_state(TRUE)

Then try to use keras again.

@alex-stanoyevitch
Copy link
Author

I just ran the first option, and tried to build the keras3 model again, but I am getting the same error mssg:

reticulate::virtualenv_remove("r-reticulate")
'''Remove virtual environment 'r-reticulate'? [Y/n]: y
Virtual environment "r-reticulate" removed.'''
model = keras_model_sequential(list(

  • layer_dense(units = 512, activation = "relu"),
  • layer_dense(units = 10, activation = "softmax")
  • ))
    '''Error in keras_model_sequential(list(layer_dense(units = 512, activation = "relu"), :
    could not find function "keras_model_sequential"'''

@alex-stanoyevitch
Copy link
Author

Oh I apologize, the keras3 error message now (above) is different.
Should I reinstall keras3 + tensorflow?

@t-kalinowski
Copy link
Member

No need to reinstall the R package. It looks like you need to restart your R session and call library(keras3)

@alex-stanoyevitch
Copy link
Author

Thank you Tomasz for all of your prompt follow-ups.
I need to leave for work now and also since today is my birthday (I'll be celebrating after work) so will get back to this tomorrow and let you know.

@t-kalinowski
Copy link
Member

Happy Birthday!

@alex-stanoyevitch
Copy link
Author

Good Morning Tomasz, I have closed all my running RStudio sessions/projects and restarted the one where I am trying to make keras3 work. I redid the library command for keras3 (as you suggested) + for tensor flow. The same code snippet (the model creation) gave an error mssg that was longer than before but the last part was the same as before; here is all the i/o:

library(keras3); library(tensorflow)

'''Attaching package: ‘tensorflow’

The following objects are masked from ‘package:keras3’:

set_random_seed, shape'''

model = keras_model_sequential(list(

  • layer_dense(units = 512, activation = "relu"),
  • layer_dense(units = 10, activation = "softmax")
  • ))
    '''2025-03-05 06:56:36.429873: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
    2025-03-05 06:56:38.208961: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
    Error in keras_model_sequential(list(layer_dense(units = 512, activation = "relu"), :
    layers must be passed in as a named argument.'''

@t-kalinowski
Copy link
Member

Hi, I can't reproduce the error locally.

Can you use reprex::reprex() to provide a reproducible example?
https://reprex.tidyverse.org/

Also, please make sure you're running the latest version of the R packages, and to help keep things reproducible, make sure you're using a reticulate-managed python installation.

remotes::install_github("rstudio/reticulate")
remotes::install_github("rstudio/keras3")
Sys.setenv("RETICULATE_PYTHON"="managed")

@alex-stanoyevitch
Copy link
Author

Hi Tomasz, I have installed the latest version of R and also of R Studio and have run those commands and the keras3 model creation command. The latter produced a new error mssg (about Python) so I am going to try to restart the R session and retry (and will let you know soon what happens. But before I do that I wanted to give you all of the outputs of the commands in your last message that you asked me to run, before they get lost after restarting R(studio):

remotes::install_github("rstudio/reticulate")
'''Downloading GitHub repo rstudio/reticulate@HEAD
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

1: All
2: CRAN packages only
3: None
4: Rcpp (1.0.13 -> 1.0.14) [CRAN]
5: rlang (1.1.4 -> 1.1.5 ) [CRAN]
6: jsonlite (1.8.9 -> 1.9.1 ) [CRAN]

Enter one or more numbers, or an empty line to skip updates: 1
Rcpp (1.0.13 -> 1.0.14) [CRAN]
rlang (1.1.4 -> 1.1.5 ) [CRAN]
jsonlite (1.8.9 -> 1.9.1 ) [CRAN]
Installing 3 packages: Rcpp, rlang, jsonlite
Installing packages into ‘C:/Users/Alex/AppData/Local/R/win-library/4.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/Rcpp_1.0.14.zip'
Content type 'application/zip' length 2901055 bytes (2.8 MB)
downloaded 2.8 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/rlang_1.1.5.zip'
Content type 'application/zip' length 1631161 bytes (1.6 MB)
downloaded 1.6 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/jsonlite_1.9.1.zip'
Content type 'application/zip' length 1107802 bytes (1.1 MB)
downloaded 1.1 MB

package ‘Rcpp’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘Rcpp’
Warning: restored ‘Rcpp’
package ‘rlang’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘rlang’
Warning: restored ‘rlang’
package ‘jsonlite’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘jsonlite’
Warning: restored ‘jsonlite’

The downloaded binary packages are in
C:\Users\Alex\AppData\Local\Temp\Rtmp0QRSA1\downloaded_packages
Running R CMD build...

  • checking for file 'C:\Users\Alex\AppData\Local\Temp\Rtmp0QRSA1\remotes662c31d450eb\rstudio-reticulate-6143cb6/DESCRIPTION' ... OK
  • preparing 'reticulate':
  • checking DESCRIPTION meta-information ... OK
  • cleaning src
  • checking for LF line-endings in source and make files and shell scripts
  • checking for empty or unneeded directories
  • building 'reticulate_1.41.0.9001.tar.gz'
    Installing package into ‘C:/Users/Alex/AppData/Local/R/win-library/4.4’
    (as ‘lib’ is unspecified)
  • installing source package 'reticulate' ...
    ERROR: cannot remove earlier installation, is it in use?
  • removing 'C:/Users/Alex/AppData/Local/R/win-library/4.4/reticulate'
  • restoring previous 'C:/Users/Alex/AppData/Local/R/win-library/4.4/reticulate'
    Warning in file.copy(lp, dirname(pkgdir), recursive = TRUE, copy.date = TRUE) :
    problem copying C:\Users\Alex\AppData\Local\R\win-library\4.4\00LOCK-reticulate\reticulate\libs\x64\reticulate.dll to C:\Users\Alex\AppData\Local\R\win-library\4.4\reticulate\libs\x64\reticulate.dll: Permission denied
    Warning messages:
    1: In file.copy(savedcopy, lib, recursive = TRUE) :
    problem copying C:\Users\Alex\AppData\Local\R\win-library\4.4\00LOCK\Rcpp\libs\x64\Rcpp.dll to C:\Users\Alex\AppData\Local\R\win-library\4.4\Rcpp\libs\x64\Rcpp.dll: Permission denied
    2: In file.copy(savedcopy, lib, recursive = TRUE) :
    problem copying C:\Users\Alex\AppData\Local\R\win-library\4.4\00LOCK\rlang\libs\x64\rlang.dll to C:\Users\Alex\AppData\Local\R\win-library\4.4\rlang\libs\x64\rlang.dll: Permission denied
    3: In file.copy(savedcopy, lib, recursive = TRUE) :
    problem copying C:\Users\Alex\AppData\Local\R\win-library\4.4\00LOCK\jsonlite\libs\x64\jsonlite.dll to C:\Users\Alex\AppData\Local\R\win-library\4.4\jsonlite\libs\x64\jsonlite.dll: Permission denied
    4: In i.p(...) :
    installation of package ‘C:/Users/Alex/AppData/Local/Temp/Rtmp0QRSA1/file662c37347026/reticulate_1.41.0.9001.tar.gz’ had non-zero exit status'''

remotes::install_github("rstudio/keras3")
'''Downloading GitHub repo rstudio/keras3@HEAD
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

1: All
2: CRAN packages only
3: None
4: rlang (1.1.4 -> 1.1.5 ) [CRAN]
5: jsonlite (1.8.9 -> 1.9.1 ) [CRAN]
6: Rcpp (1.0.13 -> 1.0.14) [CRAN]
7: glue (1.7.0 -> 1.8.0 ) [CRAN]
8: cli (3.6.3 -> 3.6.4 ) [CRAN]
9: reticulate (1.39.0 -> 1.41.0) [CRAN]

Enter one or more numbers, or an empty line to skip updates: 1
rlang (1.1.4 -> 1.1.5 ) [CRAN]
jsonlite (1.8.9 -> 1.9.1 ) [CRAN]
Rcpp (1.0.13 -> 1.0.14) [CRAN]
glue (1.7.0 -> 1.8.0 ) [CRAN]
cli (3.6.3 -> 3.6.4 ) [CRAN]
reticulate (1.39.0 -> 1.41.0) [CRAN]
Installing 6 packages: rlang, jsonlite, Rcpp, glue, cli, reticulate
Installing packages into ‘C:/Users/Alex/AppData/Local/R/win-library/4.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/rlang_1.1.5.zip'
Content type 'application/zip' length 1631161 bytes (1.6 MB)
downloaded 1.6 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/jsonlite_1.9.1.zip'
Content type 'application/zip' length 1107802 bytes (1.1 MB)
downloaded 1.1 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/Rcpp_1.0.14.zip'
Content type 'application/zip' length 2901055 bytes (2.8 MB)
downloaded 2.8 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/glue_1.8.0.zip'
Content type 'application/zip' length 184356 bytes (180 KB)
downloaded 180 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/cli_3.6.4.zip'
Content type 'application/zip' length 1393050 bytes (1.3 MB)
downloaded 1.3 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/reticulate_1.41.0.zip'
Content type 'application/zip' length 2264782 bytes (2.2 MB)
downloaded 2.2 MB

package ‘rlang’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘rlang’
Warning: restored ‘rlang’
package ‘jsonlite’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘jsonlite’
Warning: restored ‘jsonlite’
package ‘Rcpp’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘Rcpp’
Warning: restored ‘Rcpp’
package ‘glue’ successfully unpacked and MD5 sums checked
package ‘cli’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘cli’
Warning: restored ‘cli’
package ‘reticulate’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘reticulate’
Warning: restored ‘reticulate’

The downloaded binary packages are in
C:\Users\Alex\AppData\Local\Temp\Rtmp0QRSA1\downloaded_packages
Running R CMD build...

  • checking for file 'C:\Users\Alex\AppData\Local\Temp\Rtmp0QRSA1\remotes662cf392a1f\rstudio-keras3-e357997/DESCRIPTION' ... OK
  • preparing 'keras3':
  • checking DESCRIPTION meta-information ... OK
  • checking for LF line-endings in source and make files and shell scripts
  • checking for empty or unneeded directories
  • building 'keras3_1.3.0.tar.gz'
    Installing package into ‘C:/Users/Alex/AppData/Local/R/win-library/4.4’
    (as ‘lib’ is unspecified)
  • installing source package 'keras3' ...
    ** using staged installation
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
    namespace 'reticulate' 1.39.0 is being loaded, but >= 1.41.0 is required
    Calls: ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace
    Execution halted
    ERROR: lazy loading failed for package 'keras3'
  • removing 'C:/Users/Alex/AppData/Local/R/win-library/4.4/keras3'
  • restoring previous 'C:/Users/Alex/AppData/Local/R/win-library/4.4/keras3'
    Warning messages:
    1: In file.copy(savedcopy, lib, recursive = TRUE) :
    problem copying C:\Users\Alex\AppData\Local\R\win-library\4.4\00LOCK\rlang\libs\x64\rlang.dll to C:\Users\Alex\AppData\Local\R\win-library\4.4\rlang\libs\x64\rlang.dll: Permission denied
    2: In file.copy(savedcopy, lib, recursive = TRUE) :
    problem copying C:\Users\Alex\AppData\Local\R\win-library\4.4\00LOCK\jsonlite\libs\x64\jsonlite.dll to C:\Users\Alex\AppData\Local\R\win-library\4.4\jsonlite\libs\x64\jsonlite.dll: Permission denied
    3: In file.copy(savedcopy, lib, recursive = TRUE) :
    problem copying C:\Users\Alex\AppData\Local\R\win-library\4.4\00LOCK\Rcpp\libs\x64\Rcpp.dll to C:\Users\Alex\AppData\Local\R\win-library\4.4\Rcpp\libs\x64\Rcpp.dll: Permission denied
    4: In file.copy(savedcopy, lib, recursive = TRUE) :
    problem copying C:\Users\Alex\AppData\Local\R\win-library\4.4\00LOCK\cli\libs\x64\cli.dll to C:\Users\Alex\AppData\Local\R\win-library\4.4\cli\libs\x64\cli.dll: Permission denied
    5: In file.copy(savedcopy, lib, recursive = TRUE) :
    problem copying C:\Users\Alex\AppData\Local\R\win-library\4.4\00LOCK\reticulate\libs\x64\reticulate.dll to C:\Users\Alex\AppData\Local\R\win-library\4.4\reticulate\libs\x64\reticulate.dll: Permission denied
    6: In i.p(...) :
    installation of package ‘C:/Users/Alex/AppData/Local/Temp/Rtmp0QRSA1/file662c2a4c6f23/keras3_1.3.0.tar.gz’ had non-zero exit status

Sys.setenv("RETICULATE_PYTHON"="managed")
reprex::reprex()
Error in loadNamespace(x) : there is no package called ‘reprex’
install.packages("reprex")
Installing package into ‘C:/Users/Alex/AppData/Local/R/win-library/4.4’
(as ‘lib’ is unspecified)
also installing the dependencies ‘cachem’, ‘memoise’, ‘mime’, ‘sass’, ‘digest’, ‘evaluate’, ‘highr’, ‘xfun’, ‘bslib’, ‘fontawesome’, ‘htmltools’, ‘jquerylib’, ‘tinytex’, ‘callr’, ‘clipr’, ‘fs’, ‘knitr’, ‘rmarkdown’

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/cachem_1.1.0.zip'
Content type 'application/zip' length 74021 bytes (72 KB)
downloaded 72 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/memoise_2.0.1.zip'
Content type 'application/zip' length 51443 bytes (50 KB)
downloaded 50 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/mime_0.12.zip'
Content type 'application/zip' length 40893 bytes (39 KB)
downloaded 39 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/sass_0.4.9.zip'
Content type 'application/zip' length 2614594 bytes (2.5 MB)
downloaded 2.5 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/digest_0.6.37.zip'
Content type 'application/zip' length 223559 bytes (218 KB)
downloaded 218 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/evaluate_1.0.3.zip'
Content type 'application/zip' length 104115 bytes (101 KB)
downloaded 101 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/highr_0.11.zip'
Content type 'application/zip' length 44340 bytes (43 KB)
downloaded 43 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/xfun_0.51.zip'
Content type 'application/zip' length 598745 bytes (584 KB)
downloaded 584 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/bslib_0.9.0.zip'
Content type 'application/zip' length 5924490 bytes (5.7 MB)
downloaded 5.7 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/fontawesome_0.5.3.zip'
Content type 'application/zip' length 1391212 bytes (1.3 MB)
downloaded 1.3 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/htmltools_0.5.8.1.zip'
Content type 'application/zip' length 364346 bytes (355 KB)
downloaded 355 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/jquerylib_0.1.4.zip'
Content type 'application/zip' length 526152 bytes (513 KB)
downloaded 513 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/tinytex_0.56.zip'
Content type 'application/zip' length 146342 bytes (142 KB)
downloaded 142 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/callr_3.7.6.zip'
Content type 'application/zip' length 479292 bytes (468 KB)
downloaded 468 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/clipr_0.8.0.zip'
Content type 'application/zip' length 55776 bytes (54 KB)
downloaded 54 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/fs_1.6.5.zip'
Content type 'application/zip' length 415035 bytes (405 KB)
downloaded 405 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/knitr_1.49.zip'
Content type 'application/zip' length 1178623 bytes (1.1 MB)
downloaded 1.1 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/rmarkdown_2.29.zip'
Content type 'application/zip' length 2698478 bytes (2.6 MB)
downloaded 2.6 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/reprex_2.1.1.zip'
Content type 'application/zip' length 505279 bytes (493 KB)
downloaded 493 KB

package ‘cachem’ successfully unpacked and MD5 sums checked
package ‘memoise’ successfully unpacked and MD5 sums checked
package ‘mime’ successfully unpacked and MD5 sums checked
package ‘sass’ successfully unpacked and MD5 sums checked
package ‘digest’ successfully unpacked and MD5 sums checked
package ‘evaluate’ successfully unpacked and MD5 sums checked
package ‘highr’ successfully unpacked and MD5 sums checked
package ‘xfun’ successfully unpacked and MD5 sums checked
package ‘bslib’ successfully unpacked and MD5 sums checked
package ‘fontawesome’ successfully unpacked and MD5 sums checked
package ‘htmltools’ successfully unpacked and MD5 sums checked
package ‘jquerylib’ successfully unpacked and MD5 sums checked
package ‘tinytex’ successfully unpacked and MD5 sums checked
package ‘callr’ successfully unpacked and MD5 sums checked
package ‘clipr’ successfully unpacked and MD5 sums checked
package ‘fs’ successfully unpacked and MD5 sums checked
package ‘knitr’ successfully unpacked and MD5 sums checked
package ‘rmarkdown’ successfully unpacked and MD5 sums checked
package ‘reprex’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\Alex\AppData\Local\Temp\Rtmp0QRSA1\downloaded_packages'''

reprex::reprex()
'''ℹ Rendering reprex...
✔ Reprex output is on the clipboard.
(pasted from clipboard:) reprex::reprex()
#> ℹ Non-interactive session, setting html_preview = FALSE.
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> Error in switch(where, expr = stringify_expression(x_expr), clipboard = ingest_clipboard(), : EXPR must be a length 1 vector'''

library(keras3); library(tensorflow)

'''Attaching package: ‘tensorflow’

The following objects are masked from ‘package:keras3’:

set_random_seed, shape''

model = keras_model_sequential(list(

  • layer_dense(units = 512, activation = "relu"),
  • layer_dense(units = 10, activation = "softmax")
  • ))
    '''Error in py_discover_config(required_module, use_environment) :
    Python specified in RETICULATE_PYTHON (managed) does not exist'''

@alex-stanoyevitch
Copy link
Author

I've just restarted R studio and tried the Chollet book code snipet again. Now I am getting an earlier seen error mssg again:

library(keras3); library(tensorflow)

'''Attaching package: ‘tensorflow’

The following objects are masked from ‘package:keras3’:

set_random_seed, shape'''

model = keras_model_sequential(list(

  • layer_dense(units = 512, activation = "relu"),
    
  • layer_dense(units = 10, activation = "softmax")
    
  • ))
    '''2025-03-05 13:44:06.200054: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
    2025-03-05 13:44:07.282291: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
    Error in keras_model_sequential(list(layer_dense(units = 512, activation = "relu"), :
    layers must be passed in as a named argument.'''

@t-kalinowski
Copy link
Member

The repeated messages like this:

Warning: cannot remove prior installation of package ‘jsonlite’
Warning: restored ‘jsonlite’

indicate that your attempt to update R packages is not working. This is sometimes an issue on Windows, where it is not possible to delete a file while another process has the file open.

pak::pak() has some additional handling to help with this situation. Or you can make sure to update packages only in a freshly restarted R session with no R files or projects open, before any of the packages-to-be-updated have been loaded.

By the way, you can format code chunks in github with triple backticks.

@alex-stanoyevitch
Copy link
Author

Thankyou Tomasz, It is good to know why such error mssgs happen and I will next (and in the future) aim to install all R packages in a fresh empty R session--I will create a new "empty" project just for such purposes. I'll get back to you later after I try all this, and will keep my fingers crossed.

BTW, thanks for correcting my use of the wrong tic for code formatting.

@alex-stanoyevitch
Copy link
Author

Hi Tomasz, I used the first method you suggested (work on an empty RStudio project) and redid those commands you gave before. Things looked good (the packages now seemed to update correctly) so I did not save the output, closed the R session and reopened my "deep learning project" to run those commands. But I am again getting that same error mssg:

library(keras3); library(tensorflow)

Attaching package: ‘tensorflow’

The following objects are masked from ‘package:keras3’:

set_random_seed, shape
+     
+     layer_dense(units = 512, activation = "relu"),
+     layer_dense(units = 10, activation = "softmax")
+ ))```

2025-03-05 18:33:16.186836: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2025-03-05 18:33:17.966154: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
Error in keras_model_sequential(list(layer_dense(units = 512, activation = "relu"),  : 
  `layers` must be passed in as a named argument.

@alex-stanoyevitch
Copy link
Author

+     
+     layer_dense(units = 512, activation = "relu"),
+     layer_dense(units = 10, activation = "softmax")
+ ))```

2025-03-05 18:33:16.186836: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2025-03-05 18:33:17.966154: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
Error in keras_model_sequential(list(layer_dense(units = 512, activation = "relu"),  : 
  `layers` must be passed in as a named argument.

@alex-stanoyevitch
Copy link
Author

The whole code snippet (that I enclosed in triple back tics) did not paste completely in the above two attempts, here is the code:

model = keras_model_sequential(list(

  • layer_dense(units = 512, activation = "relu"),
    
  • layer_dense(units = 10, activation = "softmax")
    
  • ))

@t-kalinowski
Copy link
Member

Thanks Alex, this reminded me that the arguments to keras_model_sequential() changed in keras3. You can fix by passing layers as a named argument keras_model_sequential(layers = list(...)).

Note that that usage pattern is only used once early on for didactic purposes. The more common usage pattern is to compose with |>

keras_model_sequential() |> 
  layer_*() |>
  layer_*() ...

You may want to consult https://github.com/jonbry/deep-learning-with-R-2nd-edition-code-keras3, where @jonbry has kindly updated all code examples from the book for keras3

@alex-stanoyevitch
Copy link
Author

Many thanks Tomasz; I am delighted that it finally works now on my PCs!
Thanks also for your not having given up on me; I learned a lot of other useful things during our correspondence (including
your advice on updating R packages) and the @jonbry post will be very useful.

Best, Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants