Django 无法在 Ubuntu 上加载 SpatiaLite 库扩展 mod_spatialite
Django Unable to load the SpatiaLite library extension mod_spatialite on Ubuntu
我正在尝试 运行 带有 spatialite 的 sqlite3 但是当我 运行
$ python manage.py makemigrations
我收到错误:
django.core.exceptions.ImproperlyConfigured: Unable to load the
SpatiaLite library extension "mod_spatialite" because:
mod_spatialite.so: cannot open shared object file: No such file or
directory
我正在使用
- Ubuntu 16.04 Xenial
- Django 1.11
- Python 3.5.2
并安装了软件包:
- spatialite-bin
- spatialite-gui
- spatialite-gui-dbg
- python-pyspatialite
我也试过添加SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
,但还是不行。
我的完整回溯:
Traceback (most recent call last):
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/contrib/gis/db/backends/spatialite/base.py", line 60, in get_new_connection
cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: mod_spatialite.so: cannot open shared object file: No such file or directory
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 "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/commands/makemigrations.py", line 110, in handle
loader.check_consistent_history(connection)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/migrations/loader.py", line 282, in check_consistent_history
applied = recorder.applied_migrations()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-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 "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/base/base.py", line 229, in _cursor
self.ensure_connection()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/contrib/gis/db/backends/spatialite/base.py", line 65, in get_new_connection
six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2])
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/contrib/gis/db/backends/spatialite/base.py", line 60, in get_new_connection
cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
return Database.Cursor.execute(self, query, params)
django.core.exceptions.ImproperlyConfigured: Unable to load the SpatiaLite library extension "mod_spatialite" because: mod_spatialite.so: cannot open shared object file: No such file or directory
我通过重新安装每个包并添加我可以使用 synaptic 包管理器找到的每个 spatialite 包解决了这个问题。我安装的软件包列表:
- librasterlite2-1
- libspatialite-dbg
- libspatialite7
- libsqlite3-mod-rasterlite2
- libsqlite3-mod-spatialite
- spatialite-bin
- spatialite-gui
- spatialite-gui-dbg
- python-pyspatialite
我通过更改
解决了这个问题
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
至
SPATIALITE_LIBRARY_PATH = 'mod_spatialite.so'
根据这个comment。
您只需要通过运行以下命令安装libsqlite3-mod-spatialite:
sudo apt-get install libsqlite3-mod-spatialite
我是 运行 sqlite3 Ubuntu 20.04,加载空间扩展时出错
sqlite> SELECT load_extension('mod_spatialite');
Error: mod_spatialite.so: cannot open shared object file: No such file or directory
我已经在终端上安装了以下命令。在技术术语中,apt 为包管理提供高级接口,apt-get 提供低级接口。
sudo apt install libsqlite3-mod-spatialite
我正在尝试 运行 带有 spatialite 的 sqlite3 但是当我 运行
$ python manage.py makemigrations
我收到错误:
django.core.exceptions.ImproperlyConfigured: Unable to load the SpatiaLite library extension "mod_spatialite" because: mod_spatialite.so: cannot open shared object file: No such file or directory
我正在使用
- Ubuntu 16.04 Xenial
- Django 1.11
- Python 3.5.2
并安装了软件包:
- spatialite-bin
- spatialite-gui
- spatialite-gui-dbg
- python-pyspatialite
我也试过添加SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
,但还是不行。
我的完整回溯:
Traceback (most recent call last):
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/contrib/gis/db/backends/spatialite/base.py", line 60, in get_new_connection
cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: mod_spatialite.so: cannot open shared object file: No such file or directory
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 "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/core/management/commands/makemigrations.py", line 110, in handle
loader.check_consistent_history(connection)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/migrations/loader.py", line 282, in check_consistent_history
applied = recorder.applied_migrations()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-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 "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/base/base.py", line 229, in _cursor
self.ensure_connection()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/contrib/gis/db/backends/spatialite/base.py", line 65, in get_new_connection
six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2])
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/contrib/gis/db/backends/spatialite/base.py", line 60, in get_new_connection
cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
File "/home/marcelo/.virtualenvs/smart-eye-agora-vai/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
return Database.Cursor.execute(self, query, params)
django.core.exceptions.ImproperlyConfigured: Unable to load the SpatiaLite library extension "mod_spatialite" because: mod_spatialite.so: cannot open shared object file: No such file or directory
我通过重新安装每个包并添加我可以使用 synaptic 包管理器找到的每个 spatialite 包解决了这个问题。我安装的软件包列表:
- librasterlite2-1
- libspatialite-dbg
- libspatialite7
- libsqlite3-mod-rasterlite2
- libsqlite3-mod-spatialite
- spatialite-bin
- spatialite-gui
- spatialite-gui-dbg
- python-pyspatialite
我通过更改
解决了这个问题SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
至
SPATIALITE_LIBRARY_PATH = 'mod_spatialite.so'
根据这个comment。
您只需要通过运行以下命令安装libsqlite3-mod-spatialite:
sudo apt-get install libsqlite3-mod-spatialite
我是 运行 sqlite3 Ubuntu 20.04,加载空间扩展时出错
sqlite> SELECT load_extension('mod_spatialite');
Error: mod_spatialite.so: cannot open shared object file: No such file or directory
我已经在终端上安装了以下命令。在技术术语中,apt 为包管理提供高级接口,apt-get 提供低级接口。
sudo apt install libsqlite3-mod-spatialite