[Python-modules-team] Bug#910240: python3-django: GeoDjango incorrectly initialize spatialite (Error: /usr/lib/x86_64-linux-gnu/mod_spatialite.so: undefined symbol: sqlite3_spatialite_init)
Petter Reinholdtsen
pere at hungry.com
Wed Oct 3 19:42:42 BST 2018
Package: python3-django
Version: 1:1.10.7-2
Today I decided to test GeoDjango, and set up a simple project using
spatialite. But loading the spatialite database backend would fail like
this:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/django/contrib/gis/db/backends/spatialite/base.py", line 59, in get_new_connection
cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
File "/usr/lib/python3/dist-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: /usr/lib/x86_64-linux-gnu/libspatialite.so.7: undefined symbol: sqlite3_spatialite_init
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/usr/lib/python3/dist-packages/django/core/management/commands/makemigrations.py", line 109, in handle
loader.check_consistent_history(connection, fake_initial=True)
File "/usr/lib/python3/dist-packages/django/db/migrations/loader.py", line 277, in check_consistent_history
applied = recorder.applied_migrations()
File "/usr/lib/python3/dist-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/usr/lib/python3/dist-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/usr/lib/python3/dist-packages/django/db/backends/base/base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/lib/python3/dist-packages/django/db/backends/base/base.py", line 204, in _cursor
self.ensure_connection()
File "/usr/lib/python3/dist-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/usr/lib/python3/dist-packages/django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/lib/python3/dist-packages/django/contrib/gis/db/backends/spatialite/base.py", line 64, in get_new_connection
six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/django/contrib/gis/db/backends/spatialite/base.py", line 59, in get_new_connection
cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
File "/usr/lib/python3/dist-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
django.core.exceptions.ImproperlyConfigured: Unable to load the SpatiaLite library extension "libspatialite.so.7" because: /usr/lib/x86_64-linux-gnu/libspatialite.so.7: undefined symbol: sqlite3_spatialite_init
After asking for help om #debian-gis and reading the source of
/usr/lib/python3/dist-packages/django/contrib/gis/db/backends/spatialite/base.py,
I discovered a workaround is to add this line to settings.py:
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
According to sebastic on #debian-gis, the way to load spatialite changed
in version 4.2, and now the correct way to load the library is to use
"SELECT load_extension('mod_spatialite');", while the GeoDjango database
backend try to load it using the full path to the library file, which
for some reason is no longer working.
--
Happy hacking
Petter Reinholdtsen
More information about the Python-modules-team
mailing list