Note that there are some explanatory texts on larger screens.

plurals
  1. POInstall Spatialite for python (GeoDjango) on OS X
    text
    copied!<p>I am tearing my hair out trying to install Spatialite for GeoDjango!</p> <p>I am already using Homebrew, it's generally easy and convenient so I initially tried to follow the <a href="https://docs.djangoproject.com/en/1.6/ref/contrib/gis/install/#homebrew" rel="nofollow noreferrer">Homebrew instructions</a> for GeoDjango.</p> <p>But this stops short of installing any database, i.e. Spatialite. The next step is to try and install Spatialite itself, but there are no Homebrew-specific instructions provided by Django docs.</p> <p>I found <a href="http://www.maurobianchi.it/blog/2012/03/16/geodjango-spatialite-osx/" rel="nofollow noreferrer">this tutorial</a> which looks perfect - a Homebrew and virtualenv-friendly install of Spatialite for GeoDjango.</p> <p>But it doesn't work... it appears that my <code>pysqlite</code> is linked against the non-spatial-enabled version of SQLite that comes with OS X, rather than the Spatial-ised one I installed from Homebrew, I get this error when Django tried to connect to the db:</p> <p><em>"The pysqlite library does not support C extension loading. Both SQLite and pysqlite must be configured to allow the loading of extensions to use SpatiaLite."</em></p> <p>The author of pysqlite hasn't responded to <a href="https://github.com/ghaering/pysqlite/issues/60" rel="nofollow noreferrer">my pleas for help on Github</a> and I haven't found anything via Google.</p> <p>So I went back to the drawing board and decided to follow the <a href="https://docs.djangoproject.com/en/1.6/ref/contrib/gis/install/spatialite/#mac-os-x-specific-instructions" rel="nofollow noreferrer">"Mac OS X-specific instructions"</a> in the GeoDjango docs... by installing the various geo libs from the KyngChaos binary packages.</p> <p>The docs say "Install the packages in the order they are listed above" but I found I couldn't install <code>UnixImageIO</code> without installing <code>PROJ</code> first. The link in the docs to download Spatialite binaries (<a href="http://www.gaia-gis.it/spatialite-2.3.1/binaries.html" rel="nofollow noreferrer">http://www.gaia-gis.it/spatialite-2.3.1/binaries.html</a>) is broken so I used the "Spatialite Tools v4.1" from KyngChaos instead.</p> <p>Proceeding to the next step I get this error:</p> <pre><code>$ spatialite geodjango.db "SELECT InitSpatialMetaData();" SQLite header and source version mismatch 2013-10-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a 2013-09-03 17:11:13 7dd4968f235d6e1ca9547cda9cf3bd570e1609ef </code></pre> <p>Not really sure what's wrong at this point.</p> <p>There is someone else <a href="https://stackoverflow.com/questions/14330102/geodjango-and-spatialite-on-mac-issue-with-c-extension-loading">here on SO</a> who has gone the KyngChaos route and just ends up with the same <em>"Both SQLite and pysqlite must be configured to allow the loading of extensions"</em> error I got from the Homebrew route anyway.</p> <p>I found <a href="https://code.djangoproject.com/ticket/17756" rel="nofollow noreferrer">this ticket #17756</a> for adding <code>pyspatialite</code> support to Django - <code>pyspatialite</code> is supposed to be an easier way to <code>pip install</code> everything but unfortunately it doesn't work either (see comments towards bottom of ticket).</p> <p>I'm a bit reluctant to start trying to build everything from source by hand as it seems likely I'll just run into the same problems again, but spending hours Googling for info about cryptic compiler errors, magic flags and paths etc along the way.</p> <p>I'm about ready to give up and just use Postgres/PostGIS.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload