在Azure Databricks上安装rgdal和rgeos

3
我无法在Databricks上安装rgdal和rgeos,有什么建议吗?
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/databricks/spark/R/lib/rgdal’

configure: error: geos-config not found or not executable.
ERROR: configuration failed for package ‘rgeos’
* removing ‘/databricks/spark/R/lib/rgeos’
1个回答

3

以下是在Azure Databricks上安装rgdal和rgeos的一种方法。每次启动集群都需要执行步骤1和2,步骤1可以自动化(见下文),但步骤2需要在单独的脚本中手动执行或添加到您的R脚本顶部。

步骤1

您需要先在集群中的Linux机器上安装gdal和geos。这可以通过一个databricks notebook中的bash脚本完成。%s是一个神奇的命令,允许该单元格运行shell脚本。

%sh
#!/bin/bash

#Start by updating everything
sudo apt-get update

##############
#### rgdal

#This installs gdal on the linux machine but not the R library (done in R script)
#See https://databricks.com/notebooks/rasterframes-notebook.html
sudo apt-get install -y gdal-bin libgdal-dev

#To be able to install the R library, you also need libproj-dev 
#See https://philmikejones.me/tutorials/2014-07-14-installing-rgdal-in-r-on-linux/
sudo apt-get install -y libproj-dev 

##############
#### rgeos

#This installs geos on the linux machine but not the R library (done in R script)
#See https://philmikejones.me/tutorials/2014-07-14-installing-rgdal-in-r-on-linux/
sudo apt install libgeos++dev

然而,手动运行每次都很麻烦,所以您可以创建一个初始化脚本,在群集启动时自动运行。因此,在Databricks的Python笔记本中,将此代码复制到单元格中。在 `dbfs:/databricks/init / ` 中的脚本将在具有该名称的群集启动时运行。
#This file creates a bash script called install_packages.sh. The cluster run this file on each startup.
# The bash script will be anything inside the variable script 

clusterName = "RStudioCluster"
script = """#!/bin/bash

#Start by updating everything
sudo apt-get update

##############
#### rgdal

#This installs gdal on the linux machine but not the R library (done in R script)
#See https://databricks.com/notebooks/rasterframes-notebook.html
sudo apt-get install -y gdal-bin libgdal-dev

#To be able to install the R library, you also need libproj-dev 
#See https://philmikejones.me/tutorials/2014-07-14-installing-rgdal-in-r-on-linux/
sudo apt-get install -y libproj-dev 

##############
#### rgeos

#This installs geos on the linux machine but not the R library (done in R script)
#See https://philmikejones.me/tutorials/2014-07-14-installing-rgdal-in-r-on-linux/
sudo apt install libgeos++dev

"""
dbutils.fs.put("dbfs:/databricks/init/%s/install_packages.sh" % clusterName, script, True)

第二步

到目前为止,你已经在群集中的Linux机器上安装了gdal和geos。 在这一步中,你将安装R包rgdal。 但是,最近版本的rgdal与使用apt-get安装的最新版本的gdal不兼容。请查看此处以获取更多详细信息和替代解决方法,但如果你可以接受较旧版本的rgdal,那么最简单的解决方法是安装1.2-20版本的rgdal。您可以在databricks的R笔记本或Rstudio databricks应用程序中按如下方式执行:

require(devtools)
install_version("rgdal", version="1.2-20")
install.packages("rgeos")

设置完成

然后您可以像往常一样导入这些库:

library(rgdal)
library(rgeos)

嗨,当我运行步骤1时,出现以下错误:正在读取软件包列表... 正在构建依赖关系树... 正在读取状态信息... E: 无法定位软件包libgeos++dev - 89_Simple
我通过从这里 https://packages.ubuntu.com/bionic/libgeos++-dev 安装 libgeos++-dev 解决了这个问题。 - 89_Simple
@ThelceBear,感谢您的回答,帮助我安装了rgeos和rgdal。在Databricks上遇到了“units”的类似问题。有什么解决方法吗?很高兴提出一个新问题。 - S.Perera
抱歉,这只是我被委托为同事解决的任务。 - TheIceBear

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