Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: Spatial indexes require either `rtree` or `pygeos` in geopanda but rtree is installed

I am trying to clip spatial data in python but when I run my code...

europe = gpd.clip(worldmap, europe_bound_gdf)

... I get the error:

(ImportError: Spatial indexes require either rtreeorpygeos`.)

When I try to install rtree using:

pip3 install rtree

I'm told:

Requirement already satisfied: rtree in /Users/joshuajones/.pyenv/versions/3.9.4/lib/python3.9/site-packages (0.9.7`)

So why is my code not working?

like image 899
JoshuaAJones Avatar asked Apr 09 '21 13:04

JoshuaAJones


2 Answers

I had the same issue and this solved it for me:

pip uninstall rtree
sudo apt install libspatialindex-dev
pip install rtree

Found the answer here.

like image 144
GStav Avatar answered Sep 28 '22 20:09

GStav


In my case, the only thing that helped:

install and import condalab, run twice.

!pip install -q condacolab -q

import condacolab

condacolab.install()

install geopandas, this could take long

!conda install geopandas

import geopandas as gpd
like image 27
katze Avatar answered Sep 28 '22 21:09

katze