【问题标题】:trouble installing "sf" due to "gdal"由于“gdal”而无法安装“sf”
【发布时间】:2021-08-17 14:57:49
【问题描述】:

我无法在 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’

为什么说下载失败,然后说源码包下载好了。什么给了?

【问题讨论】:

  • 首先,不是说下载失败,而是说安装失败。此外,GDAL 是一个用于地理空间矢量操作的 C++ 库,具有一组 R 绑定。看起来您需要使用您选择的包管理器安装 GDAL,然后是 R 绑定,然后是这个 sf 包。
  • 您在 Windows 上吗?我会先尝试安装二进制文件,因为我相信它会为您提供 gdal。
  • 不,在 Mac 上。无法通过 brew 安装 gdal。不知道如何排除故障。
  • 截至 2019 年 11 月,brew install gdal 工作并解决了问题。

标签: r gdal


【解决方案1】:

遇到类似问题,我按照以下步骤操作:

  1. Terminal 上:gdalinfo --version 检查您拥有的 gdal 版本。我的是 GDAL 2.2.0,在 brew updatebrew upgrade 之后于 2017 年 4 月 28 日发布
  2. 从这里:https://github.com/r-spatial/sf,macOS 的说明,因为我已经安装了 gdal,我只使用了brew unlink gdal,然后是brew link --force gdal2
  3. 我在 R:install.packages("rgdal", repos = "http://cran.us.r-project.org", type = "source") 上重新安装了 rgdal,并确认它是使用 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... 是

之后,我安装了新版本: 图书馆(sf) 链接到 GEOS 3.6.2、GDAL 2.2.0、proj.4 4.9.3

我希望它也能成为你的解决方案。

【讨论】:

  • rgdal::getGDALVersionInfo(str = "--version") 让您确定在 rgdal 中使用了哪个版本的 GDAL。
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

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

    我有同样的问题,用这个方法解决了。

    【讨论】:

      猜你喜欢
      • 2020-12-11
      • 1970-01-01
      • 2023-03-31
      • 2011-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2018-12-24
      相关资源
      最近更新 更多