16

I am trying to install Postgis in order to use GeoDjango on OSX.

For this, I first uninstalled postgres completely, then I installed everything following the GeoDjango documentation: https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#homebrew

I did the following:

brew update
brew upgrade
brew install postgresql
brew install postgis
brew install gdal
brew install libgeoip

When I run my Django project, I get the following error:

OSError at / dlopen(/usr/local/lib/libgeos_c.so, 6): image not found

I ran

sudo find . -name "libgeos_c*"

And got:

./Library/Frameworks/GEOS.framework/Versions/3/unix/lib/libgeos_c.dylib
./Users/martin/opt/geos-3.3.0/capi/.deps/libgeos_c_la-geos_c.Plo
./Users/martin/opt/geos-3.3.0/capi/.deps/libgeos_c_la-geos_ts_c.Plo
./usr/local/Cellar/geos/3.3.3/lib/libgeos_c.1.dylib
./usr/local/Cellar/geos/3.3.3/lib/libgeos_c.a
./usr/local/Cellar/geos/3.3.3/lib/libgeos_c.dylib
./usr/local/Cellar/geos/3.3.4/lib/libgeos_c.1.dylib
./usr/local/Cellar/geos/3.3.4/lib/libgeos_c.a
./usr/local/Cellar/geos/3.3.4/lib/libgeos_c.dylib
./usr/local/Cellar/geos/3.3.5/lib/libgeos_c.1.dylib
./usr/local/Cellar/geos/3.3.5/lib/libgeos_c.a
./usr/local/Cellar/geos/3.3.5/lib/libgeos_c.dylib
./usr/local/lib/libgeos_c.1.dylib
./usr/local/lib/libgeos_c.a
./usr/local/lib/libgeos_c.dylib

As you can see, no ".so" files at all. Any suggestions?

Edit:

Out of desperation I also installed the KyngChaos Packages and added the following settings:

GEOS_LIBRARY_PATH = '/Library/Frameworks/GEOS.framework/GEOS' 
GDAL_LIBRARY_PATH = '/Library/Frameworks/GDAL.framework/GDAL' 
GEOIP_LIBRARY_PATH = '/usr/local/Cellar/geoip/1.4.8/lib/libGeoIP.dylib'

This solved the problem.

mbrochh
  • 1,011
  • 1
  • 10
  • 21
  • I did brew install geos on Mac. But the GEOS_LIBRARY_PATH is not the same on my machine as yours. Do you know, where it can be found? I tried to use find, but I couldn't find the .so file in any of the folders, which I have read permission to. I do not have sudo rights. – tommy.carstensen Sep 09 '14 at 14:19
  • You should use the libgeos_c.dylib instead of libgeos_c.so – arielkaluzhny Jul 07 '22 at 14:28

6 Answers6

23

Sorry, that KyngChaos solution completely defeats the purpose of using homebrew.

The answer for homebrew users (at least, for this one) is to uninstall geos and its dependencies and then reinstall geos and then its dependencies.

This worked for me:

brew uninstall geos gdal geoip libspatialite librasterlite spatialite-gui spatialite-tools
brew cleanup
brew install geos
brew install gdal geoip libspatialite librasterlite spatialite-gui spatialite-tools
brew cleanup

It seems some geos dependencies are getting out of sync.

You can verify the libraries that need to be installed by tracking what this returns:

python -c 'import _ctypes; _ctypes.dlopen("/usr/local/lib/libgdal.dylib")'

You'll see something like

Reason: Incompatible library version: [some geos dependent library].dylib requires version X.X.X or later, but libgeos_c.1.8.0.dylib provides version X.X.X.

brew uninstall [some geos dependency]
brew install [some geos dependency]
brew cleanup

Then rerun the above python command and either the problem will be resolved or it'll reveal another dependency to uninstall/install.

nicerobot
  • 9,145
  • 6
  • 42
  • 44
  • 1
    I think i'm close, now getting django.db.utils.OperationalError: could not access file "$libdir/postgis-2.1": No such file or directory, that python import test throws no errors. I had to uninstall postgis, brew uninstall postgis and then install it again using brew. – radtek Oct 08 '14 at 03:34
  • After spending hours, finally this saved me. – xrage May 05 '16 at 16:31
3

I solved it this way.

$ brew install postgresql
$ brew install postgis
$ brew install gdal
$ brew install libgeoip

then in Django settings set this:

GEOS_LIBRARY_PATH = '/usr/local/Cellar/geos/3.4.2/lib/libgeos_c.1.dylib'

Then it worked for me.

Houman
  • 64,245
  • 87
  • 278
  • 460
2

The installation instructions appears to hold the answer, which is to set the environment variable $GEOS_LIBRARY_PATH.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • This pointed me into the correct direction. I ignored this part of the docs because firstly it appears under the KyngChaos section (I was following the Homebrew section) and secondly it says: "If you are using a previous version of Django (like 1.0.2), then you will have to add the following in your settings" and I am using Django 1.4. Out of desperation I also tried the KyngChaos route and while it does not create the missing file, I could get it running with some additional settings. – mbrochh Jul 05 '12 at 04:00
0

Same here - after installing everything as directed, I went back and added the KyngChaos libraries, then added the three export statements to my ~/.bash_profile as listed above. This fixed my issue.

JayCrossler
  • 2,079
  • 2
  • 22
  • 22
0

I had this same issue and was able to solve it by uninstalling GDAL from Homebrew and installing the GDAL Complete package from KyngChaos: http://www.kyngchaos.com/software/frameworks

Liyosi
  • 609
  • 6
  • 5
0

Had the same issue (Mac OSX) and solved it by creating a sym link from where I found the lib folder to where python was looking for it in the error message.

ln -s /usr/local/Cellar/geos/3.10.3/lib/libgeos_c.dylib ~/PycharmProjects/project/venv/lib/libgeos_c.dylib

None of the environment variables worked, nor reinstalling

Peter
  • 284
  • 2
  • 9