5

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..

5 Answers 5

7

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:

1
  • 2
    I spent hours on this, so thanks!! Your solution still works as of 7/9/2019 on Python 3.7.3. Additionally, I'm using conda rather than venv
    – vitale232
    Commented Jul 9, 2019 at 18:32
2

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.

0

This is how to install SpatiaLite (almost) inside virtualenv for Python 3:

  1. Download cyqlite a special SQLite build with R-Tree enabled. It is required by GoeDjango.
  2. Download mod_spatialite (Windows binaries are in the pink box at the bottom of the page) i.e. mod_spatialite-[version]-win-x86.7z
  3. Unzip mod_spatialite files (flatten the tree and ignore the folder in the archive) into the virtuelenv Scripts folder.

This part I don't like but I not could find a workable solution without touching main Python3 installation.

  1. Rename or otherwise backup c:\Python35\DLLs\sqlite3.dll
  2. From cyqlite uznip sqlite3.dll file into the c:\Python35\DLLs\

Kudos: https://gis.stackexchange.com/a/169979/84121

0

I ran into this problem when trying to deploy GeoDjango on AWS Elastic Beanstalk. Turns out I needed to set SPATIALITE_LIBRARY_PATH = 'mod_spatialite.so' to SPATIALITE_LIBRARY_PATH = 'libspatialite.so' (installed at /user/lib64/libspatialite.so after running sudo yum install libspatialite and sudo yum install libspatialite-devel from my .ebextensions).

1
  • On Windows, adding SPATIALITE_LIBRARY_PATH = 'mod_spatialite' with libsqlite3-mod-spatialite installed worked for me. Note: The answer has mod_spatialite worked for me. Commented Jun 9, 2020 at 6:41
-2

HOW ACTIVATE CORRECTLY SPATIALITE IN VIRTUAL DJANGO ENVIRONNEMENT IN WINDOWS OPERATING SYSTEM LIKE 7, 8, 10

I hope my answer will come to the safety of my developer friends who use Sqlite delivered by default in django to manage their geographic data by the spatialite link which is an extension also delivered by default in python (3 or +). I'm starting from the fact that you have a preconfigured virtual environment. The first thing to do is to download two zip: sqlite-dll-win32-x86-[version].zip and mod_spatialite-[version]-win-x86.7z and unzipp this in the same directory(overwrite if there are any conflicts)

Copy all previously unzipped files into your directory and paste them into your Scripts directory of your virtual environment

It all restart your pc if necessary, deactivate and reactivate your virtual environnement and code...

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.