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

在Google Colab的R内核中无法安装exactextractr包的问题

在Google Colab R内核中安装exactextractr包失败的问题排查与解决

问题场景

在Google Colab的原生R内核Notebook中,基础R代码可正常运行:

a <- 1
print(a)

但执行install.packages("exactextractr")安装包时失败,报错显示依赖包units、sf安装存在非零退出状态,最终导致exactextractr无法安装。调用library(exactextractr)时提示包不存在。

安装包的错误输出

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

also installing the dependencies ‘proxy’, ‘e1071’, ‘wk’, ‘sp’, ‘terra’, ‘classInt’, ‘s2’, ‘units’, ‘Rcpp’, ‘raster’, ‘sf’

Warning message in install.packages("exactextractr"):
“installation of package ‘units’ had non-zero exit status”
Warning message in install.packages("exactextractr"):
“installation of package ‘sf’ had non-zero exit status”
Warning message in install.packages("exactextractr"):
“installation of package ‘exactextractr’ had non-zero exit status”

调用包的错误信息

library(exactextractr)

Error in library(exactextractr): there is no package called ‘exactextractr’
Traceback:

  1. library(exactextractr)

问题根源

Google Colab默认的R运行环境缺少units、sf这类地理空间R包所需的系统级底层依赖库:

  • units包需要libudunits2-dev
  • sf包需要libgdal-dev、libgeos-dev、libproj-dev

这些库是编译对应R包的必要条件,缺失会导致编译失败,触发非零退出状态的警告。

解决方法

先安装系统级依赖,再安装R包:

  1. 执行以下代码安装系统依赖库:
system("sudo apt-get update && sudo apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev")
  1. 重新安装exactextractr包:
install.packages("exactextractr")
  1. 验证安装成功:
library(exactextractr)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 21:15:37