AttributeError: dlsym(RTLD_DEFAULT, Error_GetLastErrorNum): symbol not found

Viewed 2900

I recently downloaded the OSMnx package to work with street networks. However, it always gives me back the error below whenever I try to import the package. I've followed several steps that people from other posts suggested, but nothing changes. If anyone has had this problem or knows a way to solve it, please share it with me. Thank you!

Traceback (most recent call last):
      File "/Users/qle/Documents/OSMnx/test.py", line 1, in <module>
        import osmnx as ox
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/osmnx/__init__.py", line 3, in <module>
        from ._api import *
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/osmnx/_api.py", line 3, in <module>
        from .bearing import add_edge_bearings
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/osmnx/bearing.py", line 9, in <module>
        from . import projection
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/osmnx/projection.py", line 3, in <module>
        import geopandas as gpd
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/geopandas/__init__.py", line 1, in <module>
        from geopandas._config import options  # noqa
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/geopandas/_config.py", line 126, in <module>
        default_value=_default_use_pygeos(),
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/geopandas/_config.py", line 112, in _default_use_pygeos
        import geopandas._compat as compat
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/geopandas/_compat.py", line 202, in <module>
        import rtree  # noqa
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/rtree/__init__.py", line 9, in <module>
        from .index import Rtree, Index  # noqa
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/rtree/index.py", line 6, in <module>
        from . import core
      File "/Users/qle/Library/Python/3.8/lib/python/site-packages/rtree/core.py", line 77, in <module>
        rt.Error_GetLastErrorNum.restype = ctypes.c_int
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 386, in __getattr__
        func = self.__getitem__(name)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 391, in __getitem__
        func = self._FuncPtr((name_or_ordinal, self))
    AttributeError: dlsym(RTLD_DEFAULT, Error_GetLastErrorNum): symbol not found
3 Answers

Your error means, that rtree, a dependency of osmnx, cannot find spatialindex.

First, make sure that spatialindex is installed:

brew install spatialindex

The next problem is that rtree only checks in very specific locations for spatialindex but brew installs to /opt/homebrew/Cellar.

You set the ENV variable and check if that's the issue with

export SPATIALINDEX_C_LIBRARY='/opt/homebrew/Cellar/spatialindex/1.9.3/lib'

python -c 'import geopandas'

and it should work. However, depending on your spatialindex and brew version, this path might change.

The problem has been solved, and I want to share in case anyone later could try if encountering the same problem. After I installed the latest version for rtree, which you can see below, it still gave me back the same problem

conda install -c ioos rtree=0.9.7

I had to install brew package for my Mac. https://brew.sh

Then I ran these 2 lines of code that my friend Philippe found from another page

Installing Rtree from libspacialindex to use .clip() in geopandas

https://github.com/gboeing/osmnx/issues/3

brew install spatialindex
pip install rtree

The problem has been solved completely.

This isn't an OSMnx issue - it's an rtree issue. You might want to open an issue directly with the rtree GitHub repo. That said, you're on OS X so you may want to try to install with rtree

conda install -c ioos rtree=0.8.2

Some of my students that have macs struggled to install rtree with pip, but succeeded with that conda command if you're on windows, you can follow these instructions to install geopandas and rtree.

reference

Related