How can I tell R where the conda environment is via a docker image?

Viewed 35

I am trying to deploy an image and test the (wonderful!) vetiver package via GitLab CI. The problem I am having is that R doesn't seem to see where my conda env is. I am trying to directly put the location into my .Renviron with echo 'RETICULATE_PYTHON = "/opt/conda/bin' > .Renviron. When I begin to deploy the image and get to my index.qmd I get this error:

Error in normalizePath(conda, winslash = "/", mustWork = TRUE) : 
  path[1]="./conda": No such file or directory

Anyone have any experience with this? Here is the gitlab-ci.yml

image: rocker/verse:4.1.2

before_script:
    - export PATH="/opt/conda/bin:$PATH"
    - apt-get update --fix-missing && apt-get install -y ca-certificates libglib2.0-0 libxext6 libsm6 libxrender1 libxml2-dev
    - apt-get install -y python3-pip python3-dev && pip3 install virtualenv
    - wget --quiet https://repo.anaconda.com/archive/Anaconda3-5.3.1-Linux-x86_64.sh -O ~/anaconda.sh
    - /bin/bash ~/anaconda.sh -b -p /opt/conda && rm ~/anaconda.sh
    - ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh
    - echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc
    - python --version
    - echo $PATH
    - echo "source activate base" > ~/.bashrc
    - echo 'RETICULATE_PYTHON = "/opt/conda/bin' > .Renviron
    - conda info --envs
    - R -e "install.packages(c('vetiver','reticulate','tidymodels','pins','dplyr','gt','quarto','checkmate'))"

Here is the index.qmd The error begins with the Python chunk...


format:
  html:
    toc: false
---

The vetiver framework is for MLOps tasks in Python and R.

> *Vetiver, the oil of tranquility, is used as a stabilizing ingredient in perfumery to preserve more volatile fragrances.*

The goal of vetiver is to provide fluent tooling to **version**, **deploy**, and **monitor** a trained model.
Functions handle both recording and checking the model's input data prototype, and predicting from a remote API endpoint.

![](images/ml_ops_cycle.png){fig-align="center" fig-alt="During the MLOps cycle, we collect data, understand and clean the data, train and evaluate a model, deploy the model, and monitor the deployed model. Monitoring can then lead back to collecting more data. There are many great tools available to understand clean data (like pandas and the tidyverse) and to build models (like tidymodels and scikit-learn). Use the vetiver framework to deploy and monitor your models."}

::: callout-tip
## Data scientists have effective tools that they ❤️ to:

-   collect data
-   prepare, manipulate, refine data
-   train models
:::

::: callout-warning
## There is a lack  of effective tools to:

-   version and publish models
-   put models into production
-   monitor model performance
:::

Use vetiver to [version](/get-started/version.html) and [deploy](/get-started/deploy.html) your trained models.

::: {.panel-tabset group="language"}
## R

```{r}
library(vetiver)
cars_lm <- lm(mpg ~ ., data = mtcars)
vetiver_model(cars_lm, "cars_linear")
```

## Python

```{python}
from vetiver import VetiverModel
from vetiver.data import mtcars
from sklearn import linear_model

model = linear_model.LinearRegression().fit(mtcars, mtcars["mpg"])
v = VetiverModel(model, model_name = "cars_linear", 
                 save_ptype = True, ptype_data = mtcars)
v.description
```
:::

and here is the error:

$ Rscript -e "quarto::quarto_render('index.qmd', output_file = 'index.html')"
processing file: index.qmd
  |..............                                                        |  20%
  ordinary text without R code
  |............................                                          |  40%
label: unnamed-chunk-2
  |..........................................                            |  60%
  ordinary text without R code
  |........................................................              |  80%
label: unnamed-chunk-4 (with options) 
List of 1
 $ engine: chr "python"
Quitting from lines 46-54 (index.qmd) 
Error in normalizePath(conda, winslash = "/", mustWork = TRUE) : 
  path[1]="./conda": No such file or directory
Calls: .main ... python_munge_path -> get_python_conda_info -> normalizePath
Execution halted
Error: System command 'quarto' failed, exit status: 1, stdout & stderr were printed
 Stack trace:
 1. quarto::quarto_render("index.qmd", output_file = "index.html")
 2. processx::run(quarto_bin, args, echo = TRUE)
 3. throw(new_process_error(res, call = sys.call(), echo = echo,  ...
 x System command 'quarto' failed, exit status: 1, stdout & stderr were printed 
Execution halted
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
0 Answers
Related