pythonsegmentation-faulthomebrewpysqlitedjango-manage.py

pysqlite segmentation fault?


I am on OSX 10.6 and have recently upgraded my Python from 2.6 to 2.7, so I had to upgrade python packages.

This time I decided to go with brew and installed sqlite, libspatialite and spatialite-tools with brew and brew doctor says everything is OK. At that time when I start my local development server (Django 1.4), it was complaining that the existing pysqlite does not support extension loading (which is required by SpatiaLite).

Then I downloaded pysqlite-2.6.3, unpacked, make the config change to enable extension loading, then did:

python setup.py build_static
python setup.py install

as described here.

When I run the dev server, now I am getting a "Segmentation Fault". As this doesn't tell much, I added settrace to Django's manage.py just after import statements:

def trace(frame, event, arg):
    print "%s, %s:%d" % (event, frame.f_code.co_filename, frame.f_lineno)
    return trace

sys.settrace(trace)

The few lines before the Segmentation Fault are as follows:

...
call, /Users/omat/workspace/devspaces/env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:71
line, /Users/omat/workspace/devspaces/env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:71
call, /Users/omat/workspace/devspaces/env/lib/python2.7/encodings/utf_8.py:15
line, /Users/omat/workspace/devspaces/env/lib/python2.7/encodings/utf_8.py:16
return, /Users/omat/workspace/devspaces/env/lib/python2.7/encodings/utf_8.py:16
return, /Users/omat/workspace/devspaces/env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:71
Segmentation fault

Any ideas on what might be wrong and some help is much appreciated. Thanks.


Solution

  • Most likely you have a non-compatible SQLite or Python SQLite native bindings libraries mixed with your Python.

    Reinstall all packages in the question after Python upgrade.

    If you want to avoid problems like this altogether my suggestion would install Python, SQLite and Python bindings using a managed environment where all the packages come from the same source, like from Homebrew.

    If you manually install packages outside this environment then make sure a correct Python libraries and Python headers are used when compiling the native libraries. I.e if you use libraries from Homebrew, use Homebrew supplied Python and Python headers, not OSX defaults.

    How to trace segfaults in Python

    http://wiki.python.org/moin/DebuggingWithGdb

    This will tell you the actual problem and the individual library in the question which is failing.