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

如何解决RStudio中安装terra包时出现的编译错误?

解决terra包安装编译错误:找不到'../tools/winlibs.R'文件

错误原因

从GitHub源码编译安装时,临时解压的包目录缺失tools/winlibs.R文件,或是路径解析错误导致无法定位该文件。

解决方案

1. 优先安装CRAN预编译二进制包

Windows环境下直接使用CRAN提供的编译完成的包,跳过源码编译环节:

install.packages("terra", type = "binary")

2. 本地克隆仓库后安装(适用于必须使用GitHub最新版本的场景)

  • 用Git克隆完整仓库到本地:
    git clone https://github.com/rspatial/terra.git
    
  • 打开R,设置工作目录到克隆的terra文件夹,执行安装:
    setwd("你本地克隆的terra文件夹路径")
    devtools::install()
    
    本地完整仓库包含所有必需文件,不会出现路径缺失问题。

3. 验证Rtools配置

  • 确认Rtools版本与R版本匹配:R 4.0.x需安装Rtools40,禁止混用其他版本
  • 检查Rtools是否正确配置:运行Sys.which("make"),若返回有效路径则配置正常;若为空,需手动将Rtools的bin目录添加到系统环境变量PATH中

用户提供的错误日志

R version 4.0.1 (2020-06-06) -- "See Things Now"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

> library(Rcpp)
> remotes::install_github("rspatial/terra")
Downloading GitHub repo rspatial/terra@HEAD
-- R CMD build ------------------------------------------------------------------------------------
v  checking for file 'C:\Users\XXXXX\AppData\Local\Temp\Rtmp2tVCLq\remotes43fc7a481e9\rspatial-terra-9494a5e/DESCRIPTION' ...
-  preparing 'terra': (3.1s)
v  checking DESCRIPTION meta-information ... 
-  cleaning src
-  checking for LF line-endings in source and make files and shell scripts (690ms)
-  checking for empty or unneeded directories (372ms)
-  building 'terra_1.7-59.tar.gz'
   警告: file 'terra/cleanup' did not have execute permissions: corrected
   警告: file 'terra/configure' did not have execute permissions: corrected
   
Installing package into ‘C:/Users/XXXXX/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
* installing *source* package 'terra' ...
** using staged installation

   **********************************************
   WARNING: this package has a configure script
         It probably needs manual configuration
   **********************************************


** libs
rm -f terra.dll RcppExports.o RcppFunctions.o RcppModule.o arith.o crs.o distRaster.o distance.o extract.o file_utils.o focal.o gcp.o gdal_algs.o gdal_multidimensional.o gdalio.o geodesic.o geos_methods.o geosphere.o math_utils.o mediancut.o memory.o movingWindow.o ncdf.o ram.o raster_methods.o raster_stats.o rasterize.o read.o read_gdal.o read_ogr.o sample.o sort.o spatBase.o spatDataframe.o spatFactor.o spatRaster.o spatRasterMultiple.o spatSources.o spatTime.o spatVector.o spatVector2.o string_utils.o vecmath.o vecmathse.o vector_methods.o write.o write_gdal.o write_ogr.o
mkdir -p ../inst
"C:/PROGRA~1/R/R-40~1.1/bin/x64/Rscript.exe" --vanilla "../tools/winlibs.R" 3.4.1
致命错误: 无法打开文件'../tools/winlibs.R': No such file or directory

make: *** [Makevars.win:27: winlibs] Error 2
ERROR: compilation failed for package 'terra'
* removing 'C:/Users/XXXXX/Documents/R/win-library/4.0/terra'
警告信息:
In i.p(...) :
  installation of package ‘C:/Users/XXXXX/AppData/Local/Temp/Rtmp2tVCLq/file43fc3a0e5fe4/terra_1.7-59.tar.gz’ had non-zero exit status
> 

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 14:33:24