rdatabricksgdalrgdalterra

Install spatial packages like terra, sf, raster had non-zero exit status on databricks


I want to install terra package and other spatial packages (raster,sf) on databricks but running into below issues. On my databricks notebook, I do

install.packages("terra")

enter image description here

Based on the error message, the gdal is not configured. I am trying to find resources online that explains to me how to resolve it. I found this page but looks like there are so many solutions but don't know which one to use. Could anyone keep me like a step-to-step guide on how to configure rgdal on databricks and install spatial R packages.

Error: gdal-config not found while installing R dependent packages whereas gdal is installed


Solution

  • I ended up doing this. At this stage, I do not know why this works but running the below commands does the job. In the databricks notebook, I did this

    %sh # this is to specify you want to run a shell command
    sudo apt update
    sudo apt-get install -y python3-dev 
    sudo apt-get install -y build-essential
    sudo apt-get install -y mysql-client 
    sudo apt update
    sudo apt-get update
    sudo apt-get install -y libssl-dev 
    sudo apt-get install -y libssl1.1 
    sudo apt-get install --allow-downgrades -y libssl1.1=1.1.1f-1ubuntu2 
    sudo apt update
    sudo apt-get install -y libmysqlclient-dev 
    sudo apt update
    sudo apt-get update
    sudo apt-get install -y libsqlite3-dev
    sudo apt-get install -y gdal-bin
    sudo apt-get install -y libgdal-dev
    sudo apt-get install -y python3-gdal
    gdal-config
    

    Then on the next cell, I did this and it managed to install terra

    %r
    install.packages("terra")