"Unable to locate the SpatiaLite library." Django
Asked Answered
R

5

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

Rather answered 30/9, 2016 at 9:4 Comment(0)
O
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:

Orthopsychiatry answered 5/10, 2016 at 19:12 Comment(1)
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 venvYarrow
T
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.

Trichite answered 25/8, 2018 at 8:8 Comment(0)
C
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

Calabresi answered 11/10, 2016 at 12:59 Comment(0)
P
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).

Perzan answered 23/1, 2019 at 5:13 Comment(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.Swanky
P
-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...

Peristyle answered 16/2, 2018 at 10:57 Comment(1)
This appears to be an incomplete rewording of pythongisandstuff.wordpress.com/2015/11/11/…, missing out important details. There is no need to restart anything.Triune

© 2022 - 2024 — McMap. All rights reserved.