You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac系统下安装R包factoextra失败的技术求助

问题描述

在Mac(arm64架构,R版本4.1)中执行命令install.packages("factoextra",repos = "http://cran.rstudio.com/")安装factoextra包失败,核心原因是编译依赖包mvtnorm、flashClust、leaps时,系统找不到/opt/R/arm64/bin/gfortran,进而导致emmeans、FactoMineR等依赖包及目标包无法完成安装。

具体报错日志

* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c lpmvnorm.c -o lpmvnorm.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c ltMatrices.c -o ltMatrices.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c miwa.c -o miwa.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c mvt.f -o mvt.o
make: /opt/R/arm64/bin/gfortran: No such file or directory
make: *** [mvt.o] Error 1
ERROR: compilation failed for package ‘mvtnorm’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/mvtnorm’
Warning in install.packages :
  installation of package ‘mvtnorm’ had non-zero exit status
* installing *source* package ‘flashClust’ ...
** package ‘flashClust’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c hc.f -o hc.o
make: /opt/R/arm64/bin/gfortran: No such file or directory
make: *** [hc.o] Error 1
ERROR: compilation failed for package ‘flashClust’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/flashClust’
Warning in install.packages :
  installation of package ‘flashClust’ had non-zero exit status
* installing *source* package ‘leaps’ ...
** package ‘leaps’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c leaps.f -o leaps.o
make: /opt/R/arm64/bin/gfortran: No such file or directory
make: *** [leaps.o] Error 1
ERROR: compilation failed for package ‘leaps’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/leaps’
Warning in install.packages :
  installation of package ‘leaps’ had non-zero exit status
ERROR: dependency ‘mvtnorm’ is not available for package ‘emmeans’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/emmeans’
Warning in install.packages :
  installation of package ‘emmeans’ had non-zero exit status
ERROR: dependencies ‘emmeans’, ‘flashClust’, ‘leaps’ are not available for package ‘FactoMineR’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/FactoMineR’
Warning in install.packages :
  installation of package ‘FactoMineR’ had non-zero exit status
ERROR: dependency ‘FactoMineR’ is not available for package ‘factoextra’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/factoextra’
Warning in install.packages :
  installation of package ‘factoextra’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/7h/gxc3t42541x2pxgl83xqfnx00000gn/T/Rtmpz8Gydy/downloaded_packages’

解决方案

1. 安装并配置gfortran

针对arm64架构的Mac,先安装适配R 4.1的gfortran版本,完成后通过软链接将其指向R期望的路径:
打开终端,执行以下命令:

# 创建目标目录(如果不存在)
sudo mkdir -p /opt/R/arm64/bin
# 将安装好的gfortran链接到指定路径(若你的gfortran安装路径不同,替换为实际路径)
sudo ln -s /usr/local/bin/gfortran /opt/R/arm64/bin/gfortran

2. 尝试安装预编译二进制包

若不想编译源码,可直接指定安装二进制包:
在R中执行:

install.packages("factoextra", repos = "http://cran.rstudio.com/", type = "binary")

若仍有依赖包需要编译,确保gfortran已配置完成后重新执行安装命令。

3. 验证安装结果

安装完成后,在R中执行以下命令确认包是否成功加载:

library(factoextra)

内容的提问来源于stack exchange,提问作者user22682286

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 09:55:36