r-treegoogle-colaboratorylibspatialindex

How to install libspatialindex on Google Colaboratory


To efficiently analyse spatial data with Python, I use the rtree spatial index library, relying on the libspatialindex C library.

I am able to successfully install rtree in the Google Colaboratory notebook using !pip install rtree.

As expected, this is not sufficient, as libspatialindex needs to be installed first, as confirmed by import rtree resulting in:

OSError: Could not find libspatialindex_c library file

I am unsure whether and how to install external libraries in the Google Collaboratory. Following https://github.com/libspatialindex/libspatialindex/wiki/1.-Getting-Started I managed to run !curl -L http://download.osgeo.org/libspatialindex/spatialindex-src-1.8.5.tar.gz | tar xz but I do not have permissions for configure: !spatialindex-src-1.8.5/configure

/bin/sh: 1: spatialindex-src-1.8.5/configure: Permission denied


Solution

  • Edit: Looks like the bug has been fixed. Building no longer requires the !mount ... command below. I've updated the example notebook accordingly.

    The original response follows.

    This looks like a Colab bug. The /content directory is mounted with noexec, which is what's causing the permissions error.

    Until that's fixed, you can remount /content with the exec permissions you need using the command:

    !mount -o remount,exec /content

    Here's a complete notebook that installs libspatialindex and rtree. https://colab.research.google.com/notebook#fileId=1N7i9zmOwVcUzd4eHWZux4p_WTBMZHi8C