0

由于缺少 sqlite 无法运行 django?实际上 sqlite 已经安装在我的系统中。

(py1)[mirror@home ci]$ python manage.py runserver
Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x9ea3d8c>>
Traceback (most recent call last):
  File "/home/mirror/build/py1/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
    self.validate(display_num_errors=True)
  File "/home/mirror/build/py1/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
    num_errors = get_validation_errors(s, app)
  File "/home/mirror/build/py1/lib/python2.7/site-packages/django/core/management/validation.py", line 23, in get_validation_errors
    from django.db import models, connection
  File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/utils.py", line 92, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/utils.py", line 24, in load_backend
    return import_module('.base', backend_name)
  File "/home/mirror/build/py1/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/mirror/build/py1/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 31, in <module>
    raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: **Error loading either pysqlite2 or sqlite3 modules** (tried in that order): No module named _sqlite3

重点是:加载 pysqlite2 或 sqlite3 模块时出错

证明已经安装了 sqlite 的证据

(py1)[mirror@home ci]$ rpm -qa | grep sqlite
python-sqlite-1.1.7-1.2.1
sqlite-devel-3.3.6-5
sqlite-3.3.6-5
(py1)[mirror@home ci]$ python -V
Python 2.7.3
(py1)[mirror@home ci]$ python manage.py runserver

那么,为什么 python manage.py runserver 失败了?

编辑 1

现在我知道我还没有构建 sqlite 模块:

(py1)[mirror@home Python-2.7.3]$ python
Python 2.7.3 (default, Sep 23 2012, 21:42:51)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mirror/insp/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/home/mirror/insp/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

我发现sqlite代码包含在python源代码中,但是如何构建它?

[mirror@home Python-2.7.3]$ ls Modules/_s
_sqlite/   _sre.c     _sre.o     _ssl.c     _struct.c
(py1)[mirror@home Python-2.7.3]$ ls Modules/_sqlite/
cache.c       connection.h  microprotocols.c  module.h            row.c           statement.c  util.h
cache.h       cursor.c      microprotocols.h  prepare_protocol.c  row.h           statement.h
connection.c  cursor.h      module.c          prepare_protocol.h  sqlitecompat.h  util.c

./configure --help | grep sqlite 什么都不返回....

(py1)[mirror@home Python-2.7.3]$ ./configure --help | grep sqlite
(py1)[mirror@home Python-2.7.3]$
4

1 回答 1

0

您需要 apt-get install libsqlite3-dev (在 debian - sqlite-devel 可能在其他地方)并重新编译 python。

于 2012-09-24T20:24:11.063 回答