【问题标题】:How to download Sf package on MacOS如何在 MacOS 上下载 Sf 包
【发布时间】:2021-09-18 00:15:30
【问题描述】:

我尝试了几个小时使用我在网上遇到的大多数解决方案来安装 sf 包(在 MacO 上),但仍然没有用。让我展示一下,我做了什么,然后一步一步出现了问题。

首先,我尝试了正常的事情install.packages("sf"),导致以下错误。

URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-2.tgz' deneniyor
Content type 'application/x-gzip' length 93022013 bytes (88.7 MB)
====================================
downloaded 65.3 MB

Warning in install.packages :
  downloaded length 68510897 != reported length 93022013
Warning in install.packages :
  URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-2.tgz': Timeout of 60 seconds was reached
Error in download.file(url, destfile, method, mode = "wb", ...) : 
  download from 'https://cran.rstudio.com/bin/macosx/contrib/4.1/sf_1.0-2.tgz' failed
Warning in install.packages :
  download of package ‘sf’ failed

之后,我尝试遵守本网站https://github.com/r-spatial/sf 中的说明。为此,我先安装了home brew,然后在MacOS终端上渲染了这两个代码。

brew install pkg-config 
brew install gdal

最后,根据网站的建议,我运行此代码来安装rgdal 包以安装sf

install.packages("rgdal", configure.args = c("--with-proj-lib=/usr/local/lib/", "--with-proj-include=/usr/local/include/"))

但是,它带有以下错误。

  There is a binary version available but the source version is later:
      binary source needs_compilation
rgdal 1.5-26 1.5-27              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘rgdal’

URL 'https://cran.rstudio.com/src/contrib/rgdal_1.5-27.tar.gz' deneniyor
Content type 'application/x-gzip' length 4391149 bytes (4.2 MB)
==================================================
downloaded 4.2 MB

* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
** using staged installation
configure: R_HOME: /Library/Frameworks/R.framework/Resources
configure: CC: clang -mmacosx-version-min=10.13
configure: CXX: clang++ -mmacosx-version-min=10.13 -std=gnu++14
configure: CFLAGS: -Wall -g -O2
configure: CPPFLAGS: -I/usr/local/include
configure: CXXFLAGS: -Wall -g -O2
configure: LDFLAGS: -L/usr/local/lib
configure: LDFLAGS: -L/usr/local/lib
configure: CXX11 is: clang++ -mmacosx-version-min=10.13, CXX11STD is: -std=gnu++11
configure: CXX is: clang++ -mmacosx-version-min=10.13 -std=gnu++11
configure: C++11 support available
configure: rgdal: 1.5-27
checking for /usr/bin/svnversion... no
configure: svn revision: 1148
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgdal’
Warning in install.packages :
  installation of package ‘rgdal’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/tc/g15hmz9s0hg1nxmh7_4mw9lm0000gn/T/RtmplfPV9h/downloaded_packages’

按照本网站https://github.com/r-spatial/sf 的建议,我也尝试了https://github.com/r-spatial/sf/issues/1536#issuecomment-727342736 中的解决方案。

然而,在第 2 部分中,当我运行此代码块时,

install.packages("rgeos", repos="http://R-Forge.R-project.org", type="source")
install.packages("rgdal", repos="http://R-Forge.R-project.org", type="source")
library(devtools)
install_github("r-spatial/sf", configure.args = "--with-proj-lib=/usr/local/lib/")

所有这些代码都出现了类似的问题。例如,对于第一个,错误是;

URL 'http://R-Forge.R-project.org/src/contrib/rgeos_0.5-8.tar.gz' deneniyor
Content type 'application/x-gzip' length 276303 bytes (269 KB)
==================================================
downloaded 269 KB

* installing *source* package ‘rgeos’ ...
** using staged installation
configure: CC: clang -mmacosx-version-min=10.13
configure: CXX: clang++ -mmacosx-version-min=10.13 -std=gnu++14
configure: rgeos: 0.5-7
checking for /usr/bin/svnversion... no
cat: inst/SVN_VERSION: No such file or directory
configure: svn revision: 
checking for geos-config... no
no
configure: error: geos-config not found or not executable.
ERROR: configuration failed for package ‘rgeos’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgeos’
Warning in install.packages :
  installation of package ‘rgeos’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/tc/g15hmz9s0hg1nxmh7_4mw9lm0000gn/T/RtmplfPV9h/downloaded_packages’

最后,我按照这个网站上的说明解决了这个问题; trouble installing "sf" due to "gdal"

首先:gdalinfo --version 代码导致 GDAL 3.3.2, released 2021/09/01 其次,我运行了brew unlink gdal,但是当我运行brew link --force gdal2 时,它不起作用。 (我是新用户,所以我认为这可能是因为版本不同,但是当我尝试 brew link --force gdal3.3.2 时,它给了我错误 Error: No such keg: /opt/homebrew/Cellar/gdal3.3.2

所以,如果你能帮助我如何在 MacOS 上安装 sf,我会很高兴的。

【问题讨论】:

  • 第一步,我建议输入options(timeout = 1200),然后输入install.packages("sf"),如果它说“你想从源代码安装需要编译的包吗?”说不”。然后,如果您需要从源代码安装软件包,我在此处发布了一组详细说明:stackoverflow.com/a/65334247/12957340(需要相当多的努力/不适用于 M1 硅 mac)
  • 嘿,非常感谢您的建议。我不知道它是怎么发生的,但现在它刚刚起作用。我怀疑这种情况下的神奇之处是否是options(timeout = 1200) 代码,但你能详细说明这段代码的作用吗? (顺便说一句,我使用的是 M1 硅 Mac,我非常希望这个问题无法解决。)
  • 根据您的错误消息,sf 包下载因“超时”而失败,即耗时超过 60 秒。将超时时间从 60 秒更改为 1200 秒似乎是一种“神奇的感觉” - 我会将评论变成答案,并提供更多详细信息供您接受(请参阅what to do when someone answers my question
  • 再次,非常感谢您的详细回答和解释。我现在明白了。
  • 没问题 - 感谢您在问题中包含所有必需的信息

标签: r macos sf


【解决方案1】:

错误消息行“install.packages 中的警告:下载长度 68510897 != 报告长度 93022013”​​和“已达到 60 秒超时”表明包没有正确下载 - 当下载时间超过 60 秒时可能会发生这种情况将软件包下载到您的计算机进行安装,即达到 60 秒的“超时”。

一种解决方案(在这种情况下有效的解决方案)是通过在运行 options(timeout = 1200) 之前运行 install.packages("sf") 来增加 R 等待下载包的时间量

如果您需要在 M1 mac 上从源代码(使用或不使用 openMP)构建包,我相信此处发布的说明有效:https://stackoverflow.com/a/68275558/12957340

【讨论】:

    猜你喜欢
    • 2020-02-09
    • 2021-05-20
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 2015-09-19
    • 2021-11-14
    • 2018-04-10
    • 1970-01-01
    相关资源
    最近更新 更多