From e4a9aa202dac1d2dc3e5be3099fcb5410fc64978 Mon Sep 17 00:00:00 2001 From: Kevin Ushey <kevinushey@gmail.com> Date: Thu, 11 Feb 2021 14:26:35 -0800 Subject: [PATCH] allow RETICULATE_PYTHON_FALLBACK as fallback Python version --- DESCRIPTION | 2 +- R/config.R | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5a03d6aa..45a9c884 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: reticulate Type: Package Title: Interface to 'Python' -Version: 1.18-9006 +Version: 1.18-9007 Authors@R: c( person("Kevin", "Ushey", role = c("aut", "cre"), email = "kevin@rstudio.com"), diff --git a/R/config.R b/R/config.R index 454917cc..141c8861 100644 --- a/R/config.R +++ b/R/config.R @@ -185,6 +185,17 @@ py_discover_config <- function(required_module = NULL, use_environment = NULL) { config <- python_config(python_version, required_module, python_version, forced = "use_python function") return(config) } + + # if RETICULATE_PYTHON_FALLBACK is specified then use it + reticulate_env <- Sys.getenv("RETICULATE_PYTHON_FALLBACK", unset = NA) + if (!is.na(reticulate_env)) { + python_version <- normalize_python_path(reticulate_env) + if (!python_version$exists) + stop("Python specified in RETICULATE_PYTHON_FALLBACK (", reticulate_env, ") does not exist") + python_version <- python_version$path + config <- python_config(python_version, required_module, python_version, forced = "RETICULATE_PYTHON_FALLBACK") + return(config) + } # create a list of possible python versions to bind to # (start with versions specified via environment variable or use_* function) -- GitLab