为 R 中的文本包构建奇点容器未找到 python 个库

Building a singularity container for the text-package in R does not find python libraries

我想为 R 中的 text 包构建一个奇点容器(使用网状结构访问 python)。构建奇点容器,安装文本包,并且可以 运行 textEmbed("hello") 作为安装过程的一部分。

但是当我启动奇点容器然后 运行:Rscript -e 'text::textEmbed("hello")'。我收到一个错误读数:

Error: Python shared library not found, Python bindings not loaded.
Use reticulate::install_miniconda() if you'd like to install a Miniconda Python environment. 

但我已确认它已安装并且 textEmbed("hello") 在安装过程的最后有效。下面是我用来构建奇点容器的文件。

Bootstrap: docker
From: ubuntu:20.04

%environment
  export LANG=C.UTF-8 LC_ALL=C.UTF-8
  export XDG_RUNTIME_DIR=/tmp/.run_$(uuidgen)

%post
    # Install
    apt-get -y update

    export R_VERSION=4.1.3
    echo "export R_VERSION=${R_VERSION}" >> $SINGULARITY_ENVIRONMENT

     # Install R
     apt-get update
     apt-get install -y --no-install-recommends software-properties-common dirmngr  wget uuid-runtime
     wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | \
       tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
     add-apt-repository \
       "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
     apt-get install -y --no-install-recommends \
     r-base=${R_VERSION}* \
     r-base-core=${R_VERSION}* \
     r-base-dev=${R_VERSION}* \
     r-recommended=${R_VERSION}* \
     r-base-html=${R_VERSION}* \
     r-doc-html=${R_VERSION}* \
     libcurl4-openssl-dev \
     libssl-dev \
     libxml2-dev \
     libcairo2-dev \
     libxt-dev \
     libopenblas-dev

    # Add a default CRAN mirror
    echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl')" >> /usr/lib/R/etc/Rprofile.site

    # Fix R package libpaths (helps RStudio Server find the right directories)
    mkdir -p /usr/lib64/R/etc
    echo "R_LIBS_USER='/usr/lib64/R/library'" >> /usr/lib64/R/etc/Renviron
    echo "R_LIBS_SITE='${R_PACKAGE_DIR}'" >> /usr/lib64/R/etc/Renviron
    # Clean up
    rm -rf /var/lib/apt/lists/*

    # Install python3
    apt-get -y install python3 wget
    apt-get -y clean

/bin/bash <<EOF
    # Install reticulate and text
    Rscript -e 'install.packages("reticulate")'
    Rscript -e 'install.packages("devtools")'
    Rscript -e 'install.packages("glmnet")'
    Rscript -e 'devtools::install_github("oscarkjell/text")'
    # Create the Conda environment at a system folder
    Rscript -e 'text::textrpp_install(prompt = FALSE)'
    Rscript -e 'text::textrpp_initialize(save_profile = TRUE, prompt = FALSE, textEmbed_test = TRUE)'
EOF

我设法通过在安装 text-package 之前安装 Miniconda 使其工作(请参阅下面的安装 Miniconda 部分)。

Bootstrap: docker
From: ubuntu:20.04

%environment
  export LANG=C.UTF-8 LC_ALL=C.UTF-8
  export XDG_RUNTIME_DIR=/tmp/.run_$(uuidgen)

%post
    # Install
    apt-get -y update

    export R_VERSION=4.1.3
    echo "export R_VERSION=${R_VERSION}" >> $SINGULARITY_ENVIRONMENT

     # Install R
     apt-get update
     apt-get install -y --no-install-recommends software-properties-common dirmngr  wget uuid-runtime
     wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | \
       tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
     add-apt-repository \
       "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
     apt-get install -y --no-install-recommends \
     r-base=${R_VERSION}* \
     r-base-core=${R_VERSION}* \
     r-base-dev=${R_VERSION}* \
     r-recommended=${R_VERSION}* \
     r-base-html=${R_VERSION}* \
     r-doc-html=${R_VERSION}* \
     libcurl4-openssl-dev \
     libssl-dev \
     libxml2-dev \
     libcairo2-dev \
     libxt-dev \
     libopenblas-dev

    # Add a default CRAN mirror
    echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl')" >> /usr/lib/R/etc/Rprofile.site

    # Fix R package libpaths (helps RStudio Server find the right directories)
    mkdir -p /usr/lib64/R/etc
    echo "R_LIBS_USER='/usr/lib64/R/library'" >> /usr/lib64/R/etc/Renviron
    echo "R_LIBS_SITE='${R_PACKAGE_DIR}'" >> /usr/lib64/R/etc/Renviron
    # Clean up
    rm -rf /var/lib/apt/lists/*

    # Install python3
    apt-get -y install python3 wget
    apt-get -y clean

    # Install Miniconda
    cd /
    wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
    bash Miniconda3-latest-Linux-x86_64.sh -b -p /miniconda

/bin/bash <<EOF
    rm Miniconda3-latest-Linux-x86_64.sh
    source /miniconda/etc/profile.d/conda.sh
    conda update -y conda
    # Install reticulate and text
    Rscript -e 'install.packages("reticulate")'
    Rscript -e 'install.packages("devtools")'
    Rscript -e 'install.packages("glmnet")'
    Rscript -e 'devtools::install_github("oscarkjell/text")'
    # Create the Conda environment at a system folder
    Rscript -e 'text::textrpp_install(prompt = FALSE)'
    Rscript -e 'text::textrpp_initialize(save_profile = TRUE, prompt = FALSE, textEmbed_test = TRUE)'
EOF