1

I am using Python3.4 on Mac OSX and I am trying to import shapely. I am however unable to do so. Here is my traceback:

    from shapely.geometry import Point
  File "/Users/tc9/Library/Python/3.4/lib/python/site-packages/shapely/geometry/__init__.py", line 4, in <module>
    from .base import CAP_STYLE, JOIN_STYLE
  File "/Users/tc9/Library/Python/3.4/lib/python/site-packages/shapely/geometry/base.py", line 9, in <module>
    from shapely.coords import CoordinateSequence
  File "/Users/tc9/Library/Python/3.4/lib/python/site-packages/shapely/coords.py", line 8, in <module>
    from shapely.geos import lgeos
  File "/Users/tc9/Library/Python/3.4/lib/python/site-packages/shapely/geos.py", line 74, in <module>
    _lgeos = load_dll('geos_c', fallbacks=alt_paths)
  File "/Users/tc9/Library/Python/3.4/lib/python/site-packages/shapely/geos.py", line 53, in load_dll
    libname, fallbacks or []))
OSError: Could not find library geos_c or load any of its variants ['/Library/Frameworks/GEOS.framework/Versions/Current/GEOS', '/opt/local/lib/libgeos_c.dylib']

I think I might have to set the GEOS_LIBRARY_PATH, but I'm not sure what to set it to.

Here is an ls of /Users/tc9/homebrew/Cellar/geos/3.4.2/lib after I did brew install geos:

libgeos-3.4.2.dylib
libgeos.dylib
libgeos_c.a
libgeos.a
libgeos_c.1.dylib
libgeos_c.dylib

I edited and sourced my ~/.profile, but that didn't solve things:

GEOS_LIBRARY_PATH="/Users/tc9/homebrew/Cellar/geos/3.4.2"
export GEOS_LIBRARY_PATH

Can anybody point me in the direction of a solution for getting shapely to import? Thanks.

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
tommy.carstensen
  • 8,962
  • 15
  • 65
  • 108
  • What is your `DYLD_LIBRARY_PATH`? And is there a `libgeos_c.dylib` in `/opt/local/lib`? –  Sep 10 '14 at 09:31
  • `/Users/tc9/homebrew/Cellar` may be where brew store things, but it uslaly makes a symbolic link to some more practical directory (without the `Cellar` directory. Do you know which directory is that? –  Sep 10 '14 at 09:32
  • @Evert echo $DYLD_LIBRARY_PATH yields a blanks line. I have not set my DYLD_LIBRARY_PATH. The folder /opt/local/bin exists, but /opt/local/lib doesn't. Doing find / -name "libgeos_c.dylib" yields /Users/tc9/homebrew/Cellar/geos/3.4.2/lib/libgeos_c.dylib and /Users/tc9/homebrew/lib/libgeos_c.dylib – tommy.carstensen Sep 10 '14 at 09:41

1 Answers1

3

You have set homebrew to install things in your home directory (well, the homebrew subdirectory in your home directory). That's ok, but you'll have to tell your system to find the installed libraries there. /opt/local/lib is commonly found automatically, but /Users/tc9/homebrew/lib won't.

So instead of setting GEOS_LIBRARY_PATH, try setting DYLD_LIBRARY_PATH as follows:

export DYLD_LIBRARY_PATH=/Users/tc9/homebrew/lib

You can do this on the command line first, and if it works, put it in your profile.

Note that I'm not using the Cellar subdirectory; you should see that as an archive for homebrew, but not as the actual files in use. For that, use /home/tc9/homebrew (with lib, bin etc appended). So for example, your PATH should also not include the Cellar directory.