8

I have a problem with GeoPandas sjoin, I work with Ubuntu and I want to use:

opolskieadresy = geopandas.sjoin(smallopolskie, adresy, how="inner", op='intersects') 

and i'm getting error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gis/.local/lib/python3.8/site-packages/geopandas/tools/sjoin.py", line 88, in sjoin
    sindex = right_df.sindex
  File "/home/gis/.local/lib/python3.8/site-packages/geopandas/base.py", line 593, in sindex
    self._generate_sindex()
  File "/home/gis/.local/lib/python3.8/site-packages/geopandas/base.py", line 98, in _generate_sindex
    sindex_cls = get_sindex_class()
  File "/home/gis/.local/lib/python3.8/site-packages/geopandas/sindex.py", line 42, in get_sindex_class
    raise ImportError(
ImportError: Spatial indexes require either `rtree` or `pygeos`. See installation instructions at https://geopandas.org/install.html

When I try to install rtree: sudo pip3 install rtee I'm getting:

Collecting rtree
  Using cached Rtree-0.9.4.tar.gz (62 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ib_695_y/rtree/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ib_695_y/rtree/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-ib_695_y/rtree/pip-egg-info
         cwd: /tmp/pip-install-ib_695_y/rtree/
    Complete output (15 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-ib_695_y/rtree/setup.py", line 3, in <module>
        import rtree
      File "/tmp/pip-install-ib_695_y/rtree/rtree/__init__.py", line 1, in <module>
        from .index import Rtree
      File "/tmp/pip-install-ib_695_y/rtree/rtree/index.py", line 6, in <module>
        from . import core
      File "/tmp/pip-install-ib_695_y/rtree/rtree/core.py", line 143, in <module>
        rt.Error_GetLastErrorNum.restype = ctypes.c_int
      File "/usr/lib/python3.8/ctypes/__init__.py", line 386, in __getattr__
        func = self.__getitem__(name)
      File "/usr/lib/python3.8/ctypes/__init__.py", line 391, in __getitem__
        func = self._FuncPtr((name_or_ordinal, self))
    AttributeError: /usr/bin/python3: undefined symbol: Error_GetLastErrorNum
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
9
  • Install Rtree or pygeos
    – gene
    Commented Nov 19, 2020 at 12:48
  • How to do it in Linux? Commented Nov 19, 2020 at 12:54
  • I got: ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output when I used pip3 install rtree. Commented Nov 19, 2020 at 13:01
  • try sudo pip3 install rtree or sudo pip3 install pygeos
    – Taras
    Commented Nov 19, 2020 at 13:09
  • 1
    Rtree Rtree requires libspatialindex
    – gene
    Commented Nov 19, 2020 at 14:30

4 Answers 4

8

Solution:

First:

sudo apt install libspatialindex-dev

Then:

sudo pip3 install rtree
3
  • 1
    This solved it for me. I had to restart the Jupyter kernel for it to detect the installation correctly though.
    – bplmp
    Commented Jan 29, 2021 at 13:50
  • @bplmp, or you can simply add %reload_ext autoreload and %autoreload 2 at the top of your jupyter file, no need to restart any kernel Commented Jul 12, 2021 at 15:43
  • sudo pip is dangerous, don't do it.
    – zabop
    Commented Feb 21, 2022 at 12:21
2

I solved pip-installing the last rtree version downloaded from https://www.lfd.uci.edu/~gohlke/pythonlibs/#rtree,

1

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
0

Install libspatialindex fixed it for me (I installed geopandas with pip).
You can try the following:

conda install -c conda-forge libspatialindex=1.9.3

If you install geopandas from conda directly, I think it should run without problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.