It appears that pyspatialite is very outdated. Do I need a special library like pyspatialite in order to use the spatial functions of spatialite? Or can I just connect to the database via the normal python driver and execute the spatial functions? If so, is there a more updated library that I am not aware of?
You can connect to Spatialite via Python using the latest version of pysqlite instead of pyspatialite. Spatialite is just the spatial enablement of SQLite so this works, but if you are connecting in this way (via pysqlite) you need to load the libspatialite extension to be able to use the spatial functionality of Spatialite.
from pysqlite2 import dbapi as sqlite conn = sqlite.connect("myDB") conn.enable_load_extension(True) conn.execute('SELECT load_extension("libspatialite-2.dll")') curs = conn.cursor() ... do something interesting
Make sure you get the correct name for the libspatialite dll which may vary depending on your version, otherwise this won't work. Scroll down on the link above and you'll find the documentation for
1Very helpful! The current import is
from pysqlite2 import dbapi2 as sqlite3. This latter for compatibility with Python 3 code.– gmas80Apr 19, 2015 at 4:17
1In case anyone falls here the import for current versions of python is
import sqlite3instead of
from pysqlite2 import dbapi as sqliteand of cource
conn = sqlite3.connect("myDB")Oct 21, 2019 at 11:57