Python, Spatialite

Python and Spatialite (32-bit) on 64-bit Windows

For some reason it is insanely difficult to use Spatialite from Python on Windows. In theory the following should create and connect to an in-memory database, then load the Spatialite extension (after mod_spatialite and friends have been put somewhere and added to your system Path):

import sqlite3

with sqlite3.connect(':memory:') as conn:

	conn.enable_load_extension(True)

	conn.execute("SELECT load_extension('mod_spatialite')")

However, this fails stating: OperationalError: The specified module could not be found.

Continue reading