5

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?

rebelliard
  • 9,592
  • 6
  • 47
  • 80
  • It's worth noting that you probably could have installed it [direct from Ubuntu's package manager](http://packages.ubuntu.com/hardy/python-pysqlite2), which might have been easier. Not that this solves your problem. – Gareth Latty Jun 19 '12 at 02:43
  • I installed the package, only that it install didn't work because from what I've read, it's precompiled without extension loading. – rebelliard Jun 19 '12 at 02:46

2 Answers2

4

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)

BradHards
  • 650
  • 9
  • 27
  • 1
    I had the same issue and wrote a guide: http://technotes.tumblr.com/post/40838871308/django-with-sqlite-as-a-geospatial-database – webjay Jan 18 '13 at 13:34
  • @webjay I tried your guide, ended up doing: ```python setup.py build #instead of build_static``` – a.m. Jul 22 '13 at 15:46
  • How do you do this without manually editing pysqlite source code? – Cerin May 01 '14 at 19:58
  • 1
    I don't think this configuration is "source code", but if you do, then I don't know. – BradHards May 01 '14 at 21:16
0

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

Hendrik F
  • 3,690
  • 3
  • 21
  • 24