0

I am running a brewed Python 2.7.11 on OS X El Capitan 10.11.3. I fail to import Shapely / GEOS:

Failed `CDLL(/usr/local/lib/libgeos_c.dylib)`
Failed `CDLL(/Library/Frameworks/GEOS.framework/Versions/Current/GEOS)`
Failed `CDLL(/opt/local/lib/libgeos_c.dylib)`
Traceback (most recent call last):
  File "example.py", line 2, in <module>
    from shapely.geometry import Point
  File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/geometry/__init__.py", line 4, in <module>
    from .base import CAP_STYLE, JOIN_STYLE
  File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/geometry/base.py", line 9, in <module>
    from shapely.coords import CoordinateSequence
  File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/coords.py", line 8, in <module>
    from shapely.geos import lgeos
  File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/geos.py", line 92, in <module>
    mode=(DEFAULT_MODE | 16))
  File "/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages/shapely/geos.py", line 61, in load_dll
    libname, fallbacks or []))
OSError: Could not find lib geos_c or load any of its variants ['/Library/Frameworks/GEOS.framework/Versions/Current/GEOS', '/opt/local/lib/libgeos_c.dylib'].

This error is strikingly similar to those reported here: Python can't import shapely and OSError geos_c could not be found when Installing Shapely. After implementing all suggestions that "did the trick" for others, I continue to get this error.

I installed geos with brew install geos today. It installed in /usr/local/Cellar/geos/3.5.0.

If I run find / -name "libgeos_c.dylib", I find three versions:

/Library/Frameworks/GEOS.framework/Versions/3/unix/lib/libgeos_c.dylib
/usr/local/Cellar/geos/3.5.0/lib/libgeos_c.dylib
/usr/local/lib/libgeos_c.dylib

Note that the last line is exactly the same path as in the first line of the error. So Python fails to import an existing file? I know it is an alias (to the file in Cellar), but would be surprised if that's the reason.

Also, $DYLD_LIBRARY_PATH and $GEOS_LIBRARY_PATH are empty at startup, but setting them to any of the following does not resolve the problem:

export DYLD_LIBRARY_PATH=/usr/local/lib
export GEOS_LIBRARY_PATH=/usr/local/Cellar/geos/3.5.0
export GEOS_LIBRARY_PATH=/usr/local/Cellar/geos/3.5.0/lib

Any insight will be tremendously welcome! This has taken me more than half of the day already...

Community
  • 1
  • 1
  • It may be worth trying the anaconda python package manager if you can't get the problem resolved. You can keep it separate from your brew environment and the packages are properly linked up to the correct (also via Anaconda) geos version. – songololo Jul 02 '16 at 05:53
  • Maybe your `DYLD_LIBRARY_PATH` is overwritten somewhere else? Maybe try `export DYLD_LIBRARY_PATH="/usr/local/lib:$DYLD_LIBRARY_PATH"` instead. – Kotaro Oct 26 '16 at 21:14
  • I ended up using Anaconda. Got it working smoothly. Thanks! – Christoph Nolte Jan 07 '17 at 22:54

0 Answers0