Question

I'm trying to get Spatialite to work with my django app, however, I've hit the following wall:

 raise ImproperlyConfigured('The pysqlite library does not support C extension loading. '
django.core.exceptions.ImproperlyConfigured: The pysqlite library does not support C extension loading. Both SQLite and pysqlite must be configured to allow the loading of extensions to use SpatiaLite.
make: *** [syncdb] Error 1

Using ubuntu 12.04, I have installed pysqlite using pip within the same user and with sudo. I have also tried compiling pysqlite and enabled extension loading myself.

Help?

Was it helpful?

Solution

The default for pysqlite is to build without extension loading support. So just rebuilding won't help. You need to change a setting (in setup.cfg).

So I'd suggest downloading as a tarball, and looking in setup.cfg:

[build_ext]
#define=
#include_dirs=/usr/local/include
#library_dirs=/usr/local/lib
libraries=sqlite3
define=SQLITE_OMIT_LOAD_EXTENSION

That last line is the problem. The easiest way is just to comment it out (add a # at the start of the line), so it looks like:

[build_ext]
#define=
#include_dirs=/usr/local/include
#library_dirs=/usr/local/lib
libraries=sqlite3
# define=SQLITE_OMIT_LOAD_EXTENSION

Then rebuild according to the instructions in the tarball (see doc/install-source.txt)

OTHER TIPS

The solution proposed here seems to apply to older systems/Python2. For newer versions of Python (e.g. 3.8), sqlite ships as part of the standard library and it's necessary to build Python with an appriopriately configured sqlite library.

For example, on MacOS using homebrew and pyenv (assuming Python dependencies are met and sqlite was installed via homebrew with extension loading enabled):

PYTHON_CONFIGURE_OPTS="--enable-loadable-sqlite-extensions --enable-optimizations --with-openssl=\$(brew --prefix openssl)" \
LDFLAGS="-L/usr/local/opt/sqlite/lib" \
CPPFLAGS="-I/usr/local/opt/sqlite/include" \
pyenv install 3.8.2

For a detailed solution, check here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top