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

Fix error when encountering Windows App Store Python #1673

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
34 changes: 30 additions & 4 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,25 @@ 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"
# 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"]
}

Expand Down Expand Up @@ -1235,3 +1245,19 @@ 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)
}


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)))
}
5 changes: 5 additions & 0 deletions R/virtualenv.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading