21

我的 rhel 5 上安装了 django 1.4。默认情况下,rhel 5 中包含 python 2.4,但要使用 django 1.4,我手动安装了 python 2.7.3 开发服务器运行良好,但是当我创建一个新项目并更改设置后。 py 文件为:

“引擎”:“django.db.backends.sqlite3”,“名称”:“/home/oracle/Desktop/test1/my.db”

现在,当我给出 python2.7 manage.py syncdb 命令时,我得到的错误是:

Traceback (most recent call last):
 File "manage.py", line 10, in <module>
   execute_from_command_line(sys.argv)
 File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py",
line 443, in execute_from_command_line
   utility.execute()
 File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py",
line 382, in execute
   self.fetch_command(subcommand).run_from_argv(self.argv)
 File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py",
line 261, in fetch_command
   klass = load_command_class(app_name, subcommand)
 File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py",
line 69, in load_command_class
   module = import_module('%s.management.commands.%s' % (app_name, name))
 File "/usr/local/lib/python2.7/site-packages/django/utils/importlib.py",
line 35, in import_module
   __import__(name)
 File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py",
line 8, in <module>
   from django.core.management.sql import custom_sql_for_model,
emit_post_sync_signal
 File "/usr/local/lib/python2.7/site-packages/django/core/management/sql.py",
line 6, in <module>
   from django.db import models
 File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py",
line 40, in <module>
   backend = load_backend(connection.settings_dict['ENGINE'])
 File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py",
line 34, in __getattr__
   return getattr(connections[DEFAULT_DB_ALIAS], item)
 File "/usr/local/lib/python2.7/site-packages/django/db/utils.py",
line 92, in __getitem__
   backend = load_backend(db['ENGINE'])
 File "/usr/local/lib/python2.7/site-packages/django/db/utils.py",
line 24, in load_backend
   return import_module('.base', backend_name)
 File "/usr/local/lib/python2.7/site-packages/django/utils/importlib.py",
line 35, in import_module
   __import__(name)
 File "/usr/local/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

请建议出路?

4

9 回答 9

25

你也可能在没有安装 sqlite 开发库的情况下手动编译了 python

所以,做

sudo apt-get install libsqlite3-dev libsqlite3

然后,重新安装python

通过输入进行测试

python
>>> import sqlite3
于 2014-01-08T15:56:19.473 回答
6

django.db.backends.sqlite3,它试图

try:
    try:
        from pysqlite2 import dbapi2 as Database
    except ImportError:
        from sqlite3 import dbapi2 as Database
except ImportError as exc:
    from django.core.exceptions import ImproperlyConfigured
    raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)

因此未安装名为sqlite3pysqlite2的模块之一。尝试安装它们

$ pip install sqlite3 # or pysqlite2

更新

sqlite3并且pysqlite2是 Python 的一部分,因此这两个包不再在PyPi中。

于 2012-05-29T10:06:00.803 回答
5

当我尝试运行 Django 开发服务器时,我收到了非常相似的错误消息:

ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): dlopen(/Users/Rubinous/Projects/Jiiri2/jiiri_venv/lib/python2.7/lib-dynload/_sqlite3.so, 2): Library not loaded: /usr/local/opt/sqlite/lib/libsqlite3.0.8.6.dylib
Referenced from: /Users/Rubinous/Projects/Jiiri2/jiiri_venv/lib/python2.7/lib-dynload/_sqlite3.so
Reason: image not found

我通过安装pysqlitePython 模块解决了这个问题pip install pysqlite

于 2013-09-08T22:23:03.837 回答
5

在 MacOSX 10.9 (Mavericks) 上,我必须运行以下命令:

CPPFLAGS=-I/usr/local/opt/sqlite/include; LDFLAGS=-L/usr/local/opt/sqlite/lib; pip install pysqlite

我使用自制软件安装 sqlite3。

brew update; brew install sqlite
于 2013-12-01T02:29:39.727 回答
4

这就是我为了让它工作而做的。

我正在使用安装了 python 2.7.5 的 pythonbrew(使用 pip)。

我首先按照 Zubair(上图)所说的做了,然后运行了这个命令:

sudo apt-get install libsqlite3-dev

然后我运行了这个命令:

pip install pysqlite

这解决了数据库问题,我在运行时得到了确认:

python manager.py syncdb
于 2013-11-02T23:33:13.743 回答
3

sqlite3是 Python 2.5 及以后版本的一部分。安装这个库:

sudo apt-get install libsqlite3-dev

或者你也可以尝试安装 Python-dev 包。

于 2012-05-28T12:14:58.467 回答
1

我在 Red Hat 上从源代码构建的 python 2.6.8 遇到了同样的问题(但这可能适用于其他操作系统上的其他版本)。

我的问题是通过在配置和构建 python之前config.status --recheck安装 sqlite-devel (Red Hat) 解决的(或者在你的构建目录中执行,然后是makeand make install.

于 2012-11-09T14:13:02.023 回答
1

FreeBSD10:适用于python3.5

pkg install py35-sqlite3
于 2016-07-10T10:04:54.380 回答
0

MordicusEtCubitus 的回答是正确的。作为一个新手,还不能投票给你。

只是为了增加您的答案,在 fedora(23) 上运行以下命令来安装。

sudo dnf install libsqlite3x-devel libsqlite3x
于 2018-08-22T12:46:42.520 回答