Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!is.null(condaenv) & !is.null(env)) {
- stop("Only one argument from condaenv and env can be different from NULL")
- }
- if (!is.null(yml) &
- is.null(condaenv) & .Platform$OS.type == "unix") {
- stop("You have to provide condaenv parameter with yml when using unix-like OS")
- }
- if (!is.null(yml)) {
- # Extracting env name form file
- name <- crete_env(yml, condaenv)
- if()
- tryCatch(
- reticulate::use_condaenv(name, required = TRUE),
- error = function(e) {
- warning(e, call. = FALSE)
- stop(
- "reticulate is unable to set new environment due to already using other python.exe, please restart R session. See warnings() for original error",
- call. = FALSE
- )
- }
- )
- }
- if (!is.null(condaenv) & is.null(yml)) {
- tryCatch(
- reticulate::use_condaenv(condaenv, required = TRUE),
- error = function(e) {
- warning(e, call. = FALSE)
- stop(
- "reticulete is unable to set new environment due to already using other python.exe, please restart R session. See warnings() for original error",
- call. = FALSE
- )
- }
- )
- }
- if (!is.null(env)) {
- tryCatch(
- reticulate::use_virtualenv(env, required = TRUE),
- error = function(e) {
- warning(e, call. = FALSE)
- stop(
- "reticulete is unable to set new environment due to already using other python.exe, please restart R session. See warnings() for original error",
- call. = FALSE
- )
- }
- )
- }
- tryCatch(
- model <- reticulate::py_load_object(path),
- error = function(e) {
- if (grepl("UnicodeDecodeError", e)) {
- warning(paste(e), call. = FALSE)
- warning(
- "There is a problem with encoding mismatch. You are probably using Python 3.x and are trying to load Python 2.7 object.
- Try to use virtual environment with matching encoding.",
- call. = FALSE
- )
- }
- else if (grepl("No module", e)) {
- warning(paste(e), call. = FALSE)
- warning(
- "Your Python environment is missing some modules. Please install them using \n conda install name_of_missing_module \n or \n pip install name_of_missing_module " ,
- call. = FALSE
- )
- }
- else{
- warning(paste(e), call. = FALSE)
- }
- stop(
- "Yours environment has to match environment where pickle file was created. It also includes encoding, python version, and libraries version. Specifying .yml file or path to virtual environment may help. For more information look warnings() and then ?scikitlearn_model",
- call. = FALSE
- )
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement