2

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

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
MartinT
  • 1,671
  • 3
  • 14
  • 14

1 Answers1

6

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

Bob Smith
  • 36,107
  • 11
  • 98
  • 91
  • thanks for a fantastic response, this helps a lot. ONe minor additional question - is there a way to persist this install between notebooks ( collab newbie here, so I am not sure). I acknowledge that this follow up question is OOT – MartinT Jan 18 '18 at 03:32
  • The easiest way to configure it probably to add a cell at the top in a collapsed section that performs the install if needed, e.g., https://colab.research.google.com/notebook#fileId=1BawUdNVyRKl87_jVYEXCL3BXC14SW2AX – Bob Smith Jan 18 '18 at 05:19
  • Yes, that would do it, but takes a lot of time and seems unnecessary between repeated use of the notebook. – MartinT Jan 19 '18 at 05:56
  • Hi, I am having problem to fix this error: SError: Could not find libspatialindex_c library file, i followed the notebook recommended here to install that library, but it still keep showing. I have to say that this error didnt appear before, i mean, i run one notebook without problems, and then i try to run it again, and this error showed up, and now I haven't get rid of it. Any advice will be welcome. – Bayes Aug 11 '19 at 00:35
  • To run the notebook you need the specify the version for RTree !pip install "rtree>=0.8,<0.9" – JNZ Apr 23 '20 at 19:17
  • I was able to simply run `!apt-get install -y libspatialindex-dev` on a Colab notebook. – Joe Germuska Aug 16 '20 at 22:50