“Unable to locate the SpatiaLite library.” Django

妖精的绣舞 提交于 2019-12-10 16:49:17

问题


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


回答1:


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



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




回答3:


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




回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/39787700/unable-to-locate-the-spatialite-library-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!