使用apptainer构建容器时出现R依赖错误

问题描述 投票:0回答:2

我正在使用 apptainer 在服务器上的 Ubuntu 中构建 r-text 包容器。有人可以帮忙吗?我的硬件是 Mac pro M1,配备 MacOS 13.4 (22F66)。

我的build.def文件如下。该容器基于 docker Ubuntu 镜像。我尝试先安装 r,然后安装必要的软件包。然后我需要安装文本包和conda。

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.2.2
    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 \
     libharfbuzz-dev \
     libfribidi-dev \
     libgit2-dev \
     libxml2-dev \
     libfontconfig1-dev \
     libssl-dev \
     libxml2-dev \
     libfreetype6-dev \
     libpng-dev \
     libtiff5-dev \
     libjpeg-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("pkgdown")'
     Rscript -e 'install.packages("ragg")'
     Rscript -e 'install.packages("textshaping")'
     Rscript -e 'install.packages("reticulate")'
     Rscript -e 'install.packages("devtools")'
     Rscript -e 'install.packages("glmnet")'
     Rscript -e 'install.packages("tidyverse")'
#     Rscript -e 'install.packages("text")'
     Rscript -e 'devtools::install_github("oscarkjell/text")'
     # Create the Conda environment at a system folder
     Rscript -e 'text::textrpp_install(prompt = FALSE, rpp_version = c("torch==1.11.0", "transformers==4.19.2", "numpy", "nltk"))'
     Rscript -e 'text::textrpp_initialize(save_profile = TRUE, prompt = FALSE, textEmbed_test = TRUE)'
     Rscript -e 'text::textEmbed("hello", model = "distilbert-base-cased", layers = 5)'
     Rscript -e 'text::textEmbed("hello", model = "bert-base-cased", layers = 11)'
     Rscript -e 'text::textEmbed("hello", model = "bert-large-cased", layers = 23)'
     Rscript -e 'text::textEmbed("hello", model = "roberta-base", layers = 11)'
     Rscript -e 'text::textEmbed("hello", model = "roberta-large", layers = 23)'
     Rscript -e 'text::textEmbed("hello", model = "google/flan-t5-base", layers = -2)'
     Rscript -e 'text::textEmbed("hello", model = "google/flan-t5-large", layers = -2)'
     Rscript -e 'text::textEmbed("hello", model = "bigscience/T0pp", layers = -2)'
     Rscript -e 'text::textEmbed("hello", mdoel = "xlm-roberta-base", layers=-2)'
     Rscript -e 'text::textEmbed("hello", mdoel = "xlm-roberta-large", layers=-2)'
     Rscript -e 'text::textEmbed("hej", mdoel = "KB/bert-base-swedish-cased", layers=-2)'
     Rscript -e 'text::textEmbed("hello", mdoel = "nghuyong/ernie-2.0-base-en", layers=-2)'

使用此文件,我然后运行 Linux 命令来构建容器:apptainer container.sif build.def。服务器返回以下错误消息。

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 r-recommended : Depends: r-cran-mgcv (>= 1.1.5) but it is not going to be installed
                 Depends: r-cran-rpart (>= 3.1.20) but it is not going to be installed
                 Depends: r-cran-survival (>= 2.13.2-1) but it is not going to be installed
                 Depends: r-cran-mass but it is not going to be installed
                 Depends: r-cran-class but it is not going to be installed
                 Depends: r-cran-matrix but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
FATAL:   While performing build: while running engine: exit status 100
r text apptainer
2个回答
0
投票

使用以下代码替换以“apt-get install -y --no-install-recommends ...”开头的 apt-get 代码。

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 \
libharfbuzz-dev \
libfribidi-dev \
libgit2-dev \
libxml2-dev \
libfontconfig1-dev \
libssl-dev \
libxml2-dev \
libfreetype6-dev \
libpng-dev \
libtiff5-dev \
libjpeg-dev \
r-cran-mgcv \
r-cran-rpart \
r-cran-survival \
r-cran-mass \
r-cran-class \
r-cran-matrix

此外,将导出 R_VERSION=4.2.2 升级为导出 R_VERSION=4.3.0。

看起来有效。


0
投票

我知道这样做可能很奇怪,但我找不到其他地方可以问。您设法使用正常方式安装 devtools,但由于某种原因,我的一些软件包(特别是 devtools 和 sf)没有以这种方式安装。为什么?您的代码中的内容允许正确安装所有软件包。我有一个简单的代码,只需

引导程序:docker 来自:r-base:4.3.2

R -e "install.packages('raster')" # worked
R -e "install.packages('devtools')" # worked
R -e "install.packages('sf')" # worked
© www.soinside.com 2019 - 2024. All rights reserved.