Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unable to locate the SpatiaLite library." Django

I'm trying to make Django's SQLite3 accept spatial queries. This tutorial suggests that I add this to settings:

SPATIALITE_LIBRARY_PATH = 'mod_spatialite'

Which produces this error:

django.core.exceptions.ImproperlyConfigured: Unable to load the SpatiaLite library extension "mod_spatialite" because: The specified module could not be found.

I also tried doing this :

SPATIALITE_LIBRARY_PATH = r'C:\\Program Files (x86)\\Spatialite\\mod_spatialite-4.3.0a-win-x86\\mod_spatialite-4.3.0a-win-x86\\mod_spatialite.dll'

If I don't add this variable I receive this error when I migrate:

django.core.exceptions.ImproperlyConfigured: Unable to locate the SpatiaLite library. Make sure it is in your library path, or set SPATIALITE_LIBRARY_PATH in your settings.

Thank you..

like image 939
Seio. E. Avatar asked Sep 30 '16 09:09

Seio. E.


2 Answers

Amusingly enough 5 days later I'm having the same issue. After a little bit of poking around I got it working:

Set

SPATIALITE_LIBRARY_PATH = 'mod_spatialite'

and extract ALL the DLL files from the mod_spatialite-x.x.x-win-x86.7z to your Python installation directory. The dll's apparently need to be in the same folder with python.exe. Also I imagine the mod_spatialite package needs to 32/64 bit according to your python installation. If you're missing some dll's, you get the same error "specified module not found" regardless of what dll file is missing, so it's a bit misleading.

Downloaded from http://www.gaia-gis.it/gaia-sins/

I used mod_spatialite stable version 4.3.0a x86 with Python 3.5.2 32-bit.

Other threads on the same issue with all sorts of answers:

  • Use spatialite extension for SQLite on Windows
  • Getting a working SpatiaLite + SQLite system for x64 c#
  • https://gis.stackexchange.com/questions/85674/sqlite-python-2-7-and-spatialite
like image 121
voneiden Avatar answered Oct 17 '22 02:10

voneiden


On Ubuntu18.04, adding SPATIALITE_LIBRARY_PATH = 'mod_spatialite.so' with libsqlite3-mod-spatialite installed worked for me.

Note: The answer has mod_spatialite, while for me mod_spatialite.so worked.

like image 2
atb00ker Avatar answered Oct 17 '22 00:10

atb00ker