我在 Ubuntu 20.04 LTS 操作系统上运行 Miniconda3,并在 conda 环境中安装了 R-4.0.3。当我尝试通过 R 提示符从 CRAN 存储库安装软件包时,我得到一个
x86_64-conda-linux-gnu-c++: not found
我已经按照内置 gcc 工具链的 Anaconda 文档中的建议运行了
source activate qwe
(qwe
是环境的名称)。我还运行了 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
感谢@merv,我了解了使用 conda 构建环境的不同方法,并成功实现了我的目标。他发布了一个链接,指向他关于使用具有特定编译器和依赖项的
environment.yaml
文件进行构建的答案之一。我还学到了一些有价值的东西:“最好将源库的频道保持在最低限度。在之前的安装中,我结合了默认值、r
、pypi
和conda-forge
频道”。在这个成功的设置中,只有 conda-forge
和 pypi
。
以下是我在 miniconda3 安装中使 R 编译正常工作所遵循的步骤。
(base) $ rm -rf ~/miniconda3
export PATH="~/miniconda3/bin:$PATH"
(这是必要的,因为在安装时,我已经对 conda init 说“是”)
重新安装 miniconda3(下载后和安装前确保进行 SHA256 测试以确保文件完整性 - 我的第一次下载已损坏)
使用下面的
asd
创建了一个新环境.yaml
。我本次练习的目标是使用 rpy2
和 pybrms
让 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
(base) $ source activate asd # this changes the prompt to (asd) $
r-v8
、r-rcpp
和 r-rcpparmadillo
(asd) $ conda install -c conda-forge r-v8 # repeat for r-rcpp & r-rcpparmadillo
(asd) $ R
启动 R 以进入 R 提示符并运行install.packages("bayesm") # this was a package from CRAN that was failing compilation as a source package
这是我最近三天进行的测试,以测试 conda 环境中的 R 如何访问内置 gcc 编译器而不是系统编译器
quit()
(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 的新用户,这既令人沮丧,又令人受益匪浅。我希望这对另一个新用户有用。
如果您在 Conda 环境中有 R,我强烈建议避免通过
utils::install.packages
安装。相反,通过 Conda 安装。许多 CRAN 软件包可通过 Conda Forge 渠道获得,通常在软件包名称前添加“r-”。所以,尝试一下吧
conda install -n qwe -c conda-forge r-bayesem
Step1:在主目录中找到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++
Step2:将
/home/showteth/anaconda3/envs/r351/bin
添加到 .Renviron
(在您的主目录中)
echo 'PATH=${PATH}:/home/showteth/anaconda3/envs/r351/bin' >> .Renviron
Step3:重启rstudio服务器使配置生效
如果使用 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")
这是 VS Code 中问题的[解决方案][1],对我来说效果很好,但您可能需要将页面翻译成英文。 [1]:https://blog.csdn.net/weixin_64316191/article/details/128945014
检查Makeconf文件中的第180行错误:
sed -n '180 p' ~/miniforge3/envs/R/lib/R/etc/Makeconf
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c $< -o $@
less -N ~/miniforge3/envs/R/lib/R/etc/Makeconf
CC 最有可能位于 16 号线或 17 号线附近 修改一下:
vim ~/miniforge3/envs/R/lib/R/etc/Makeconf
使用绝对路径将
CC=x86_64-conda-linux-gnu-cc
替换为 CC=~/miniforge3/envs/R/bin/x86_64-conda-linux-gnu-cc
。