-
Notifications
You must be signed in to change notification settings - Fork 85
Description
related also to this issue and maybe this is just more details on this specific issue.
When you try to deploy an app that has ragnar as a dependency AND you have used ragnar in a way that generated the ephemeral python environment as described in the original issue, you get the following error during deployment to Connect.
ℹ Capturing R dependencies from renv.lock
✔ Found 72 dependencies
Error inpythonConfig():
! Failed to detect python environment
Caused by error insystem2():
! error in running command
Backtrace:
▆
- ├─rsconnect::deployApp(...)
- │ └─rsconnect:::bundleApp(...)
- │ └─rsconnect:::createAppManifest(...)
- │ └─rsconnect (local) pythonConfig(appDir)
- │ ├─base::withCallingHandlers(...)
- │ └─rsconnect:::inferPythonEnv(appDir, python = python, forceGenerate = forceGenerate)
- │ └─base::system2(...)
- └─rsconnect (local)
<fn>(<cmdError>)- └─cli::cli_abort("Failed to detect python environment", parent = err)
└─rlang::abort(...)Execution halted
This happens because python is retrieved by the
getPythonfunction when the option of"rsconnect.python.enabledis set toTRUE.pythonEnabled <- getOption("rsconnect.python.enabled", !targetIsShinyapps) if (pythonEnabled) { getPython(path)The function
rsconnect::inferPythonEnvuses the value ofpython = getPython(), which will return NULL in this case, since it is just using the callSys.getenv("RETICULATE_PYTHON"). The method used byreticulatedescribed in the original issues above does not set any environment variables. Additionally, conda is not used in this case either.The way
inferPythonEnvworks, is shown below:rsconnect:::inferPythonEnv function (workdir, python = getPython(), forceGenerate = FALSE) { env_py <- system.file("resources/environment.py", package = "rsconnect") args <- c(shQuote(env_py), if (forceGenerate) "-f", shQuote(workdir)) hasConda <- is_installed("reticulate") && reticulate::py_available(initialize = FALSE) && reticulate::py_config()$anaconda if (hasConda) { prefix <- getCondaEnvPrefix(python) conda <- getCondaExeForPrefix(prefix) args <- c("run", "-p", prefix, python, args) output <- system2(command = conda, args = args, stdout = TRUE, stderr = NULL, wait = TRUE) } else { output <- system2(command = python, args = args, stdout = TRUE, stderr = NULL, wait = TRUE) }So when python is NULL and conda is not used, the
system2(command = python, ....will fail with the error I pasted above.It is interesting, since in logical case where conda exists, the python is extracted from the
reticulate::py_config()$anacondavariable.So perhaps the
inferPythonEnvfunction should instead be using thereticulate::py_config()$pythonlocation whenreticulateis installed, like this?hasVirtualEnv <- is_installed("reticulate") && reticulate::py_available(initialize = FALSE) && !reticulate::py_config()$anaconda if(hasVirtualEnv) python <- reticulate::py_config()$pythonSince
reticulateis already a suggested package, and in this case, you are already checking forreticulatebeing installed, perhaps this logical case would properly find the python reticulate is using in a cleaner way?
Tagging @t-kalinowski, @aronatkins and @nealrichardson since I discussed this issue with them.
Originally posted by @SokolovAnatoliy in #1143