由于 "gdal" 的问题,安装 "sf" 出现了麻烦。

31

我无法在R上安装"sf"包。看起来与gdal有关的问题。不知道如何解决。

> install.packages("sf")

  There is a binary version available but the source version is later:
   binary source needs_compilation
sf  0.4-3  0.5-1              TRUE

Do you want to install from sources the package which needs compilation?
y/n: y
installing the source package ‘sf’

trying URL 'https://cran.rstudio.com/src/contrib/sf_0.5-1.tar.gz'
Content type 'application/x-gzip' length 4073881 bytes (3.9 MB)
==================================================
downloaded 3.9 MB

* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
configure: CC: clang
configure: CXX: clang++
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘sf’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/sf’
Warning in install.packages :
  installation of package ‘sf’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/1m/w_zt5ygd26n_87h41qf574wc0000gn/T/RtmpNlYbwT/downloaded_packages’

为什么下载失败,但是显示源代码包已经下载完成?这是怎么回事?

1
首先,它并没有说下载失败,而是安装失败。此外,GDAL是一个用于地理空间矢量操作的C++库,并带有一组R绑定。看起来您需要使用您选择的软件包管理器安装GDAL,然后安装其R绑定,最后再安装这个sf包。 - Sebastian Lenartowicz
你使用的是Windows系统吗?我建议你先尝试安装二进制文件,因为我相信这将为你提供gdal。 - jsta
不,我在Mac上。无法通过brew安装gdal。不确定如何进行故障排除。 - invictus
2
截至2019年11月,“brew install gdal”可行,并解决了该问题。 - peak
3个回答

22

面对类似的问题,我按照以下步骤进行了操作:

  1. 终端中输入gdalinfo --version命令检查您使用的GDAL版本。我的版本是GDAL 2.2.0,发布于2017/04/28,通过执行brew updatebrew upgrade得到。
  2. https://github.com/r-spatial/sf下载macOS版,并按照说明进行安装。由于我已经安装了GDAL,所以我只执行了brew unlink gdal然后执行brew link --force gdal2
  3. 重新在R上安装rgdal:install.packages("rgdal", repos = "http://cran.us.r-project.org", type = "source") 确认编译时使用了configure: GDAL: 2.2.0
  4. 最后,执行install.packages("sf") ,它需要被编译:binary source needs_compilation sf 0.5-3 TRUE
  5. 再次确认configure: GDAL: 2.2.0checking GDAL version >= 2.0.0... yes

之后,我成功安装了新版本:library(sf) Linking to GEOS 3.6.2, GDAL 2.2.0, proj.4 4.9.3

希望这也能为您提供解决方案。


2
rgdal::getGDALVersionInfo(str = "--version") 可以让你确定在 rgdal 中使用的 GDAL 版本。 - Elin

2

sf的GitHub页面提供了安装说明,其中包括一些关于此问题的信息。除了按照那里的步骤使用brew安装gdal之外,我还必须单独安装proj:

https://github.com/r-spatial/sf


0

实际上,一个简单的解决方法是从CRAN下载sf文件,然后手动安装它。

我遇到了同样的问题,并使用这种方法解决了它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接