Skip to content

Commit f816ed7

Browse files
authored
Update create_virtualenv.R
Signed-off-by: Jessica Ikechukwu <Jessica.Ikechukwu@uwe.ac.uk>
1 parent 8ff9a92 commit f816ed7

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

R/create_virtualenv.R

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@ acro_venv <- "r-acro"
22
acro_package <- "acro==0.4.11"
33
python_version <- ">=3.10"
44

5-
65
#' Install acro
76
#'
87
#' @param envname the name of the Python virtual environment
8+
#' @param python the path to Python executable
99
#' @param ... Any other parameters.
1010
#'
1111
#' @return No return value, called for side effects
12-
13-
14-
install_acro <- function(envname = "r-acro", ...) {
12+
install_acro <- function(envname = "r-acro", python = NULL, ...) {
13+
# Get Python executable if not provided
14+
if (is.null(python)) {
15+
python <- Sys.which("python3")
16+
if (python == "") {
17+
python <- Sys.which("python")
18+
}
19+
if (python == "") {
20+
stop("Python not found in PATH. Please ensure Python is installed and accessible.")
21+
}
22+
}
23+
1524
# create Python virtual environment
1625
reticulate::virtualenv_create(
1726
envname = envname,
18-
version = python_version,
27+
python = python,
1928
force = TRUE,
2029
packages = NULL
2130
)
22-
2331
# install Python acro
2432
reticulate::py_install(acro_package, envname = envname)
2533
}
@@ -29,13 +37,17 @@ install_acro <- function(envname = "r-acro", ...) {
2937
#' @param ... Any other parameters.
3038
#'
3139
#' @return No return value, called for side effects
32-
3340
create_virtualenv <- function(...) {
41+
# Get Python executable path
42+
python_path <- Sys.which("python3")
43+
if (python_path == "") {
44+
python_path <- Sys.which("python")
45+
}
46+
3447
# ensure a virtual environment exists
3548
if (!reticulate::virtualenv_exists(acro_venv)) {
36-
install_acro(envname = acro_venv)
49+
install_acro(envname = acro_venv, python = python_path)
3750
}
38-
3951
# activate virtual environment
4052
reticulate::use_virtualenv(acro_venv, required = TRUE)
4153
}

0 commit comments

Comments
 (0)