我使用的是 OSX 10.6,最近将 Python 从 2.6 升级到了 2.7,因此我必须升级 python 软件包。
这次我决定使用brew,并使用brew安装了sqlite、libspatialite和spatialite-tools,并且brew doctor
说一切正常。当时,当我启动本地开发服务器(Django 1.4)时,它提示现有的 pysqlite 不支持扩展加载(这是 SpatiaLite 所需的)。
然后我下载了 pysqlite-2.6.3,解压,更改配置以启用扩展加载,然后执行以下操作:
python setup.py build_static
python setup.py install
如上所述here 。
当我运行开发服务器时,现在出现“段错误”。由于这并不能说明什么,我添加了 settrace在 import 语句之后到 Django 的 manage.py:
def trace(frame, event, arg):
print "%s, %s:%d" % (event, frame.f_code.co_filename, frame.f_lineno)
return trace
sys.settrace(trace)
段错误之前的几行如下:
...
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
非常感谢任何有关可能出现问题的想法和一些帮助。谢谢。
最佳答案
很可能您的 Python 中混合了不兼容的 SQLite 或 Python SQLite native 绑定(bind)库。
Python升级后重新安装问题中的所有包。
如果您想完全避免此类问题,我的建议是使用托管环境安装 Python、SQLite 和 Python 绑定(bind),其中所有包都来自同一源,例如 Homebrew。
如果您在此环境之外手动安装软件包,请确保在编译 native 库时使用正确的 Python 库和 Python header 。也就是说,如果您使用 Homebrew 中的库,请使用 Homebrew 提供的 Python 和 Python header ,而不是 OSX 默认值。
如何在 Python 中跟踪段错误
http://wiki.python.org/moin/DebuggingWithGdb
这将告诉您实际的问题以及问题中失败的各个库。
关于python - pysqlite 段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12368491/