无法在Ubuntu Conda环境中编译R软件包:x86_64-康达-Linux-gnu-c ++:未找到

dojqjjoe  于 2023-01-12  发布在  Linux
关注(0)|答案(4)|浏览(1014)

我在Ubuntu 20.04 LTS操作系统上运行Miniconda 3,并且在conda环境中安装了R-4.0.3,当我尝试通过R提示符从CRAN存储库安装软件包时,我收到一个

x86_64-conda-linux-gnu-c++: not found

我已经按照Anaconda文档中关于内置gcc工具链的建议运行了source activate qweqwe是环境的名称),还运行了source activate root,并使用conda install gxx_linux-64安装了编译器工具链
我的$PATH返回以下内容:

/home/sreedta/miniconda3/envs/qwe/bin:/home/sreedta/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

下面是我尝试安装名为bayesm的软件包时的完整输出

> install.packages("bayesm")
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://cloud.r-project.org/src/contrib/bayesm_3.1-4.tar.gz'
Content type 'application/x-gzip' length 2269364 bytes (2.2 MB)
==================================================
downloaded 2.2 MB

* installing *source* package ‘bayesm’ ...
** package ‘bayesm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
x86_64-conda-linux-gnu-c++ -std=gnu++11 -I"/home/sreedta/miniconda3/envs/qwe/lib/R/include" -DNDEBUG -I../inst/include/ -I'/home/sreedta/miniconda3/envs/qwe/lib/R/library/Rcpp/include' -I'/home/sreedta/miniconda3/envs/qwe/lib/R/library/RcppArmadillo/include' -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/sreedta/miniconda3/envs/qwe/include -I/home/sreedta/miniconda3/envs/qwe/include -Wl,-rpath-link,/home/sreedta/miniconda3/envs/qwe/lib   -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/sreedta/miniconda3/envs/qwe/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/r-base_1603047469992/work=/usr/local/src/conda/r-base-4.0.3 -fdebug-prefix-map=/home/sreedta/miniconda3/envs/qwe=/usr/local/src/conda-prefix  -c RcppExports.cpp -o RcppExports.o
/bin/sh: 1: x86_64-conda-linux-gnu-c++: not found
make: *** [/home/sreedta/miniconda3/envs/qwe/lib/R/etc/Makeconf:180: RcppExports.o] Error 127
ERROR: compilation failed for package ‘bayesm’
* removing ‘/home/sreedta/miniconda3/envs/qwe/lib/R/library/bayesm’
* restoring previous ‘/home/sreedta/miniconda3/envs/qwe/lib/R/library/bayesm’

The downloaded source packages are in
        ‘/tmp/Rtmp6hsphd/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages("bayesm") :
  installation of package ‘bayesm’ had non-zero exit status
tp5buhyn

tp5buhyn1#

多亏了@merv,我了解了使用conda构建环境的不同方法,并成功地实现了我的目标。他发布了一个链接,指向他关于使用特定编译器和依赖项构建environment.yaml文件的答案之一。我还学到了一些有价值的东西:“* 最好将源代码库的通道保持在最小值。在以前的安装中,我将默认通道rpypiconda-forge组合在一起”*。在这次成功的安装中,只有conda-forgepypi
下面是我在miniconda 3安装中为R正确编译所遵循的步骤。
1.已完全删除现有安装:

(base) $ rm -rf ~/miniconda3

1.我还从/etc/profile和~/.bashrc中删除了以下行

export PATH="~/miniconda3/bin:$PATH"

(this是必要的,因为在安装时,我已经对conda init说“是”)
1.重新安装miniconda 3(下载后和安装前,请确保您做了sha 256测试,以确保文件完整性-我的第一次下载已损坏)
1.使用下面的.yaml创建了一个新的环境asd。我的目标是使用rpy2pybrms使R和Python能够相互协作。

name: asd
channels:
  - conda-forge   # @merv had mentioned as best source for R related stuff
  - defaults      # only conda-forge has R-base=4.0.3 so defaults are second
  - dependencies: # this is where I added the gcc suite of libraries per @merv
  - python=3.6.11
  - libcurl
  - libv8
  - libgcc-ng  # gcc c
  - libgfortran-ng # gcc fortran
  - libgfortran4   # gcc fortran
  - libglib        # also needed for gcc (I could be wrong)
  - libstdcxx-ng   # gcc c++ / g++
  - conda
  - pip
  - wheel
  - r-base=4.0.3   # default channels only go as high as R-base=3.6.1.
  - pip:
      - rpy2==3.3.6
      - pybrms==0.0.33

1.当仍然处于(base)$ prompt时,I source使用以下命令激活了新环境

(base) $ source activate asd # this changes the prompt to (asd) $

1.然后我直接从conda-forge安装了以下3R包r-v8r-rcppr-rcpparmadillo

(asd) $ conda install -c conda-forge r-v8  # repeat for r-rcpp & r-rcpparmadillo

1.在(asd)$提示符下,我使用(asd) $ R启动R以到达R提示符并运行

install.packages("bayesm")  # this was a package from CRAN that was failing compilation as a source package
  • 这是我在过去3天中执行的测试,用于测试conda环境中的R如何访问内置gcc编译器而不是系统编译器 *

1.我在R提示符下使用quit()退出R
quit()
1.返回(asd) $提示符以安装更多R软件包

(asd) $ conda install -c conda-forge boost-cpp # prerequisite for r-bh

(asd) $ conda install -c conda-forge r-bh # prerequisite for r-brms

这将安装一大堆R库。
作为一个在新操作系统(Linux-Ubuntu)上使用Anaconda、R和Python的新用户,这既令人沮丧,也让人受益匪浅。

83qze16e

83qze16e2#

如果您在Conda环境中安装了R,我强烈建议您避免通过utils::install.packages安装,而是通过Conda安装。许多CRAN包可以通过Conda Forge频道获得,通常包名前面带有“r-”。

conda install -n qwe -c conda-forge r-bayesem
p1tboqfb

p1tboqfb3#

步骤1:在主目录中查找 x86_64-conda-linux-gnu-c++

[showteth@localhost ~] find ~ -name "x86_64-conda-linux-gnu-c++"
/home/showteth/anaconda3/envs/r351/bin/x86_64-conda-linux-gnu-c++

步骤2:将/home/showteth/anaconda3/envs/r351/bin添加到.Renviron(在主目录中)

echo 'PATH=${PATH}:/home/showteth/anaconda3/envs/r351/bin' >> .Renviron

步骤3:重新启动rstudio服务器以使配置生效

wtzytmuj

wtzytmuj4#

如果使用rstudio-server/rstudio IDE安装软件包失败,请尝试在不使用IDE的R控制台中安装r软件包

mamba activate r_test
 mamba install -c conda-forge gxx_linux-64
 R
 # install package in R native console, not in rstudio/rstudio-server
 BiocManager::install("ClassDiscovery")

相关问题