Django with SQLite as a geospatial database

For testing purposes I wanted to use SQLite to speed up the tests, so this post sums up what I had to do.

Most of it is inspired by GeoDjango with spatialite on OSX.

Download pysqlite:

tar -xzvf pysqlite-2.6.3.tar.gz
cd pysqlite-2.6.3

Edit setup.cfg and out comment define=SQLITE_OMIT_LOAD_EXTENSION so it looks like:


Build it:

python build_static
python install

Create spatial metadata tables:

touch /tmp/test.db
spatialite /tmp/test.db "SELECT InitSpatialMetaData();"

Don’t mind the error table spatial_ref_sys already exists.

Now back to your project and in your relevant you need:

DATABASES['default'] = {
    'ENGINE': 'django.contrib.gis.db.backends.spatialite',
    'NAME': '/tmp/test.db'

Done. I hope?


  1. technotes posted this