23

My only line of code is

import geopandas

and it gives me the error

OSError: Could not find libspatialindex_c library file

has anyone encountered this before? my script was working just fine until this error came up.

**Note that rtree module not found was an issue fisrt, and upon installation I received the above error instead.

jrowley
  • 347
  • 2
  • 6

4 Answers4

20

I had the same issue while working in Linux Subsystem at Windows 10 (speaking about this). What helped was installing the version for developers using apt. Namely:

sudo apt install libspatialindex-dev did the job.

I did not need to work with make.

edit: Nice to see my answer has been upvoted so many times; in the time of writing it, however, this was not the most popular answer and it was preceeded by the other answers that suggested using make. This is why I am referring to this command; and I think the other answers are worth reading anyway.

Community
  • 1
  • 1
Vojta F
  • 534
  • 3
  • 17
14

If you are using MacOS, it's as simple as follow:

brew install spatialindex
pip install rtree

If you are working on linux environment you have to build this from source:

  1. Install spatialindex

    curl -L https://github.com/libspatialindex/libspatialindex/archive/1.8.5.tar.gz | tar xz
    cd libspatialindex-1.8.5/
    ./autogen.sh
    ./configure
    make
    sudo make install
    sudo ldconfig
    
  1. install rtree: pip install rtree
Community
  • 1
  • 1
Dhia
  • 10,119
  • 11
  • 58
  • 69
  • 2
    This worked for me on my mac and after quite a while, trying to find a solution (including editing the core.py file in rtree) I am very greatful. I conda installed geopandas, pip installed osmnx, brew installed spatialindex, pip uninstalled rtree and then pip installed rtree and it worked. – Jack Jun 12 '18 at 18:30
  • 2
    Left out one step: need to run `./autogen.sh` before you can `./configure`. – Keith Devens Aug 17 '18 at 00:24
6

Linux installation steps for Docker users:

RUN apt-get update
RUN apt-get install -y --fix-missing curl autoconf libtool automake
RUN curl -L https://github.com/libspatialindex/libspatialindex/archive/1.8.5.tar.gz | tar -xz
RUN cd libspatialindex-1.8.5 && ./autogen.sh && ./configure && make && make install && ldconfig
Community
  • 1
  • 1
user667489
  • 9,501
  • 2
  • 24
  • 35
1

User DYZ provided the correct answer in the comments.

You need to install spatialindex.

This question should be set to answered so it is not misleading

Dhia
  • 10,119
  • 11
  • 58
  • 69
Worm
  • 1,313
  • 2
  • 11
  • 28