[Python] Pass python location to Rscript in Azure Devops

Discussão em 'Python' iniciado por Stack, Setembro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I need to create an Azure Devops pipeline to build and deploy an R Shiny app (not python-shiny). The main problem in my case is that I don't have admin rights on the build agents. To mitigate this, I use a folder where I have full sudo rights ($(Pipeline.Workspace)/R/library).

    And for app restore and snapshot, I use this pipeline:

    steps:
    - checkout: self
    - script: |
    #Use system-installed Python 3.10.18
    /usr/bin/python3.10 --version
    which python3.10
    # Navigate to repo root directory
    cd $(Pipeline.Workspace)/s
    # Create virtual environment
    [ -d venv ] || python3.10 -m venv venv
    # Activate virtual environment
    source venv/bin/activate
    # Upgrade pip & install dependencies
    python -m pip install -U pip
    pip3 install cmake
    # Install renv and restore the package in $(Pipeline.Workspace)/R/library
    Rscript -e 'dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE, showWarnings = FALSE)'
    Rscript -e '.libPaths(Sys.getenv("R_LIBS_USER")); install.packages("renv", lib = Sys.getenv("R_LIBS_USER"), repos = "https://cloud.r-project.org")'
    Rscript -e '.libPaths(Sys.getenv("R_LIBS_USER")); renv::snapshot()'
    Rscript -e '.libPaths(Sys.getenv("R_LIBS_USER")); renv::restore()'
    # Install rsconnect to deploy app
    ##code to deploy using rsconnect
    displayName: 'Install and restore R environment'
    env:
    R_LIBS_USER: $(Pipeline.Workspace)/R/library


    The only problem here is that R and Rscript don't see a system Python3 installed when it's trying to run renv restore:

    The following required system packages are not installed:
    - cmake [required by arrow]
    - python2 [required by reticulate]
    The R packages depending on these system packages may fail to install.

    An administrator can install these packages with:
    - sudo dnf install python2 cmake

    - The library is already synchronized with the lockfile.


    Please note that the minimum requirement for the reticulate package is Python 2.7, and all our team members use at least Python 3.10.

    As a result, in deployment logs, I see this error:

    Error : Installation of Python not found, Python bindings not loaded.
    See the Python "Order of Discovery" here: https://rstudio.github.io/reticulate/articles/versions.html#order-of-discovery.
    [rsc-session] Received signal: interrupt
    [rsc-session] Terminating subprocess with interrupt ...


    Is it possible to somehow pass the Python location to renv and Rscript before restore and a snapshot?

    Continue reading...

Compartilhe esta Página