Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.
This repository was archived by the owner on Jan 6, 2026. It is now read-only.

Issue with importing sklearn (missing) and creating python env through Basilisk #9

Description

@laurensvdwiel

Dear Dev team,

Following the guideline provided in https://dzhang32.github.io/dasper/articles/dasper.html

When at the https://dzhang32.github.io/dasper/articles/dasper.html#running-dasper code block I receive the following error on my HPC setup.

Error: BiocParallel errors
  2 remote errors, element index: 1, 2
  0 unevaluated and other errors
  first remote error:
Error in py_get_attr(x, name, FALSE): AttributeError: module 'sklearn' has no attribute 'ensemble'
Run `reticulate::py_last_error()` for details.

The issue is related to not being able to set a user-provided python environment and basilisk is not working as intended at:

dasper/R/utils.R

Lines 264 to 289 in ec5f82a

.outlier_score <- function(features, ...) {
cl <- basilisk::basiliskStart(env_sklearn)
outlier_scores <- basilisk::basiliskRun(cl, function() {
sklearn <- reticulate::import("sklearn")
od_model <- sklearn$ensemble$IsolationForest()
od_model <- od_model$set_params(...)
od_model_params <- od_model$get_params()
od_model <- od_model$fit(features)
outlier_scores <- od_model$decision_function(features)
suppressWarnings(
print(stringr::str_c(
Sys.time(), " - fitting outlier detection model with parameters: ",
stringr::str_c(names(od_model_params), "=", unname(od_model_params)) %>%
stringr::str_c(collapse = ", ")
))
)
return(outlier_scores)
})
basilisk::basiliskStop(cl)
return(outlier_scores)
}

I have created a local, user-based (and yes, horrible) fix, but at least now I am able to run the code. local Fix, changed :

.outlier_score <- function(features, ...) {
    reticulate::use_python("/home/bin/python3")
    sklearn <- reticulate::import("sklearn")
    od_model <- sklearn$ensemble$IsolationForest()
    od_model <- od_model$set_params(...)
    od_model_params <- od_model$get_params()
    od_model <- od_model$fit(features)
    outlier_scores <- od_model$decision_function(features)

    suppressWarnings(
        print(stringr::str_c(
       	    Sys.time(), " - fitting outlier detection model with parameters: ",
            stringr::str_c(names(od_model_params), "=", unname(od_model_params)) %>%
                stringr::str_c(collapse = ", ")
        ))
    )

   return(outlier_scores)
}

Note my python has already pandas and sklearn installed, but a newer version. forcing reticulate to use that and removing all cl/basilisk language provides a temporary fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions