From 39eff672de83dc50913a56edc925eb426f6d4fc1 Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Wed, 18 Sep 2024 15:14:40 -0400 Subject: [PATCH 1/4] Don't error when discovering Python --- R/config.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/R/config.R b/R/config.R index 947ee3c7..0b81f746 100644 --- a/R/config.R +++ b/R/config.R @@ -368,11 +368,16 @@ py_discover_config <- function(required_module = NULL, use_environment = NULL) { # path translation going to and from msys2 currently not implemented. # E.g.: "C:\foo\bar" -> "/c/foo/bar" and "/foo/bar" -> "C:\rtools43\foo\bar" # https://github.com/rstudio/reticulate/issues/1325 - python_sys_platforms <- vapply( - python_versions, system2, "", - args = c("-c", shQuote("import sys; print(sys.platform)")), - stdout = TRUE) + get_platform <- function(python) { + tryCatch({ + system2(python, + args = c("-c", shQuote("import sys; print(sys.platform)")), + stdout = TRUE, stderr = FALSE) + }, warning = function(w) "", error = function(e) "") + } + python_sys_platforms <- vapply(python_versions, get_platform, "") + python_versions <- python_versions[python_sys_platforms != ""] python_versions <- python_versions[python_sys_platforms != "cygwin"] } From b828fe7043238c71e51bad9484316704469ecd7c Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Wed, 18 Sep 2024 15:15:39 -0400 Subject: [PATCH 2/4] Don't discover Windows App Store Pythons --- R/config.R | 16 ++++++++++++++++ R/virtualenv.R | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/R/config.R b/R/config.R index 0b81f746..48158d33 100644 --- a/R/config.R +++ b/R/config.R @@ -364,6 +364,11 @@ py_discover_config <- function(required_module = NULL, use_environment = NULL) { size <- ifelse(is.na(info$size), 0, info$size) python_versions <- python_versions[size != 0] + + # We should not automatically discover windows app store python + python_versions <- + python_versions[!is_windows_app_store_python(python_versions)] + # remove msys2 / cygwin python executables. # path translation going to and from msys2 currently not implemented. # E.g.: "C:\foo\bar" -> "/c/foo/bar" and "/foo/bar" -> "C:\rtools43\foo\bar" @@ -1240,3 +1245,14 @@ py_session_initialized_binary <- function() { # return python_binary } + + +is_windows_app_store_python <- function(python) { + # There is probably a better way, but don't currently have + # access to a windows machine with the app store installed. + python <- normalizePath(python, winslash = "/", mustWork = FALSE) + grepl("/Program Files/WindowsApps/PythonSoftwareFoundation.Python", + python, fixed = TRUE) +} + + diff --git a/R/virtualenv.R b/R/virtualenv.R index 454517e8..2a97a311 100644 --- a/R/virtualenv.R +++ b/R/virtualenv.R @@ -648,6 +648,11 @@ virtualenv_starter <- function(version = NULL, all = FALSE) { rownames(starters) <- NULL } + if (is_windows()) { + # Windows App Store Python should never be used. + starters <- starters[!is_windows_app_store_python(starters$path), ] + } + if (all) starters else if (nrow(starters)) From 729ccfd4e2a903baeeebdfc107b22ca434620ba5 Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Wed, 18 Sep 2024 15:16:21 -0400 Subject: [PATCH 3/4] internal utility. --- R/config.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/config.R b/R/config.R index 48158d33..bdb0c6e0 100644 --- a/R/config.R +++ b/R/config.R @@ -1256,3 +1256,8 @@ is_windows_app_store_python <- function(python) { } +find_all_pythons <- function(root = "/") { + cmd <- sprintf("find %s -type f -regex '.*/python[0-9.]*$' -executable 2>/dev/null", + root) + as.character(suppressWarnings(system(cmd, intern = TRUE))) +} From 1141b5cd27bdda5de29f5ac1918ce274123dcbb8 Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Wed, 18 Sep 2024 15:23:27 -0400 Subject: [PATCH 4/4] Add NEWS --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index c87421d2..c6b768ae 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # reticulate (development version) +- Fixed error where `py_discover_config()` attempted to detect + Windows App Store Python installations, which are now excluded + from discovery by both `py_discover_config()` and `virtualenv_starter()` + (#1656, #1673). + - Fixed error when converting an empty NumPy char array to R (#1662). - Fixed error when using reticulate with radian (#1668, #1670).