rtree: rtree version 0.9 install error: OSError: libspatialindex_c.so: cannot open shared object file

Hi, running pip install "rtree>=0.8,<1" fails with this error:

Collecting rtree<1,>=0.8
  Downloading https://files.pythonhosted.org/packages/5e/64/a01a6675c39ddfba2467cc6b432ce9af2e71a3a67e9e8ace106ccda10df8/Rtree-0.9.0.tar.gz (52kB)
    100% |████████████████████████████████| 61kB 2.7MB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-r2lpov2a/rtree/setup.py", line 3, in <module>
        import rtree
      File "/tmp/pip-build-r2lpov2a/rtree/rtree/__init__.py", line 1, in <module>
        from .index import Rtree
      File "/tmp/pip-build-r2lpov2a/rtree/rtree/index.py", line 6, in <module>
        from . import core
      File "/tmp/pip-build-r2lpov2a/rtree/rtree/core.py", line 104, in <module>
        rt = ctypes.CDLL(lib_name)
      File "/usr/local/lib/python3.6/ctypes/__init__.py", line 348, in __init__
        self._handle = _dlopen(self._name, mode)
    OSError: libspatialindex_c.so: cannot open shared object file: No such file or directory

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-r2lpov2a/rtree/

I installed libspatialindex_c.so manually by running the following, but the above error still happens even though /usr/local/lib/libspatialindex_c.so exists now :

LIBSPATIALINDEX_VERSION=spatialindex-src-1.8.5
curl -sLO "http://download.osgeo.org/libspatialindex/$LIBSPATIALINDEX_VERSION.tar.gz" && \
    tar xzf "$LIBSPATIALINDEX_VERSION.tar.gz" && \
    rm -rf "$LIBSPATIALINDEX_VERSION.tar.gz" && \
    cd "$LIBSPATIALINDEX_VERSION" && \
    ./configure && \
    make -j $( getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1 ) && \
    make install

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted comments

worth mentioning that pip install "rtree>=0.8,<0.9"works. this only happens on version 0.9

The package that must be installed on trusty is libspatialindex-c3 and libspatialindex-c4v5 on 16.04 and 18.04

Seeing the same issue as of this morning on our CI server.

The system (running Scientific Linux 7) has libspatialindex v1.8.5 installed:

$ yum list installed | grep "spatialindex"
spatialindex.x86_64                   1.8.5-1.el7                 @epel

However, I have no shared library named libspatialindex_c.so, but instead libspatialindex_c.so.4:

$ locate spatialindex_c
/usr/lib64/libspatialindex_c.so.4
/usr/lib64/libspatialindex_c.so.4.1.0

The changes in this diff resulted in rtree being hardcoded to import spatialindex_c.so, rather than calling ctypes.util.find_library("spatialindex_c"), which was previously returning the correct name:

>>> import ctypes.util
>>> ctypes.util.find_library("spatialindex_c")
'libspatialindex_c.so.4'

@hobu - latest master installs without error, unlike 0.9.0. Thanks!

Appears that there was a change in Python 3.6 to cause find_library to search LD_LIBRARY_PATH: https://hg.python.org/cpython/rev/385181e809bc

I wonder if you could make more people happy with a fallback if find_library doesn’t get a result:

lib_name = find_library('spatialindex_c')
if not lib_name:
    if 'linux' in sys.platform:
        lib_name = 'libspatialindex_c.so'
    elif 'darwin' in sys.platform:
        lib_name = 'libspatialindex_c.dylib'
    else:
        lib_name = 'libspatialindex_c'

Of course, that still doesn’t work if you’ve got a libspatialindex_c.so.4 in a non-standard location (luckily, I don’t!).