我在我的rhel 5上安装了django 1.4。默认情况下,rhel 5中有python 2.4但是要使用django 1.4我手动安装了python 2.7.3 开发服务器运行正常,但是当我创建一个新项目并将settings.py文件更改为:
之后'ENGINE':'django.db.backends.sqlite3', 'NAME':'/ 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
请建议出路?
答案 0 :(得分:22)
您可能还手动编译了python而没有安装sqlite开发库
所以,做
sudo apt-get install libsqlite3-dev libsqlite3
然后,重新安装python
输入
进行测试python
>>> import sqlite3
答案 1 :(得分: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)
因此未安装名为 sqlite3 或 pysqlite2 的模块之一。 尝试安装它们
$ pip install sqlite3 # or pysqlite2
<强>更新强>
sqlite3
和pysqlite2
是Python的一部分,因此这两个软件包不再位于PyPi中。
答案 2 :(得分: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
我通过使用pysqlite
安装pip install pysqlite
Python模块解决了这个问题。
答案 3 :(得分:5)
在MacOSX 10.9(Mavericks)上,我必须运行此命令:
CPPFLAGS=-I/usr/local/opt/sqlite/include; LDFLAGS=-L/usr/local/opt/sqlite/lib; pip install pysqlite
我用homebrew安装sqlite3。
brew update; brew install sqlite
答案 4 :(得分:4)
这就是我为了让它发挥作用所做的。
我正在使用安装了python 2.7.5的pythonbrew(使用pip)。
我首先做了Zubair(上图)所说的并运行了这个命令:
sudo apt-get install libsqlite3-dev
然后我运行了这个命令:
pip install pysqlite
这解决了数据库问题,我在运行时得到了确认:
python manager.py syncdb
答案 5 :(得分:3)
答案 6 :(得分:1)
我在Red Hat上从源代码构建的python 2.6.8遇到了同样的问题(但这可能适用于其他操作系统上的其他版本)。
我的问题是通过安装sqlite-devel(Red Hat)之前配置和构建python(或在构建目录中执行config.status --recheck
,然后是make
和{ {1}}。
答案 7 :(得分:0)
FreeBSD10 :对于 python3.5
pkg install py35-sqlite3
答案 8 :(得分:0)
MordicusEtCubitus的答案是正确的。还不能成为新手吗?
只需添加到您的答案中,在fedora(23)上运行以下命令即可安装。
sudo dnf install libsqlite3x-devel libsqlite3x