Sunday, November 23, 2014

libspatialite problem with Django on OS X

I have no idea how it comes, using GeoDjango on OS X is a kind of pain in ass, especially when it's about spatialite. It has got better and better - it's better at least rather than the time you should install all related package manually. Finally, our awesome friend Homebrew became to be able to handle most of these cumbersome works, but I should say - it's very close.

You can face this error message when you're trying to make GIS Django application on OS X:

Unable to load the SpatiaLite library extension "/usr/local/lib/libspatialite.dylib"

If you install libspatialite 4.2.0 package by using Homebrew, then it installs libspatialite.dylib and mod_spatialite.dylib into its library path. When django.contrib.gis.db.backends.spatialite is used as a database backend, I'm not sure what happens on extension loading logic of sqlite3, it tries to find `sqlite3_spatialite_init` symbol from libspatialite.dylib. But that symbol dwells in mod_spatialite.dylib, so it fails. You can adjust this by adding SPATIALITE_LIBRARY_PATH to settings.py file:

SPATIALITE_LIBRARY_PATH='/usr/local/lib/mod_spatialite.dylib'

For sure, it can vary with the library path. Real path would be /usr/local/Cellar/libspatialite/x.x.x/lib/. (x.x.x is version number)

No comments:

Post a Comment