【发布时间】:2012-05-05 11:18:00
【问题描述】:
我在设置空间数据库并将其与 GeoDjango 同步时遇到了麻烦。我能够根据 geodjango 文档设置空间数据库并创建一个 django 应用程序,但是当我运行时
python manage.py sqlall world
我收到了,
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/smaranh/django-env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/smaranh/django-env/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 "/home/smaranh/django-env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/smaranh/django-env/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 "/home/smaranh/django-env/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/smaranh/django-env/local/lib/python2.7/site-packages/django/core/management/commands/sqlall.py", line 4, in <module>
from django.core.management.sql import sql_all
File "/home/smaranh/django-env/local/lib/python2.7/site-packages/django/core/management/sql.py", line 6, in <module>
from django.db import models
File "/home/smaranh/django-env/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/home/smaranh/django-env/local/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/smaranh/django-env/local/lib/python2.7/site-packages/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/smaranh/django-env/local/lib/python2.7/site-packages/django/db/utils.py", line 44, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named psycopg2.extensions
我累了,真的不知道该怎么办?请帮忙
编辑
好的,我找到了这个link,它告诉我出了什么问题。现在,当我从 \home 进入 python 并执行 import psycopg2 它不会给我任何 ImportError 但是当我在虚拟环境中时,我得到 ImportError
(django-env)smaranh@ubuntu:~/geodjango$ python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named psycopg2
现在链接指导我如何附加路径,但我并不真正理解这个过程,因为我是新手,我不想进一步搞砸它。那么有人可以逐步指导我如何附加sys.path??
【问题讨论】:
-
你能把 DATABASES 值贴在你的 settings.py 上吗?
-
DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'geodjango', # Or path to database file if using sqlite3. 'USER': 'smaranh', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } -
@dannyroa 我想我找到了答案,刚刚编辑了我的帖子,你能帮我理解它并让我知道我应该如何继续吗?
-
diegueus9 的回答应该有效。不过,您可能会在 Mac 上安装它时遇到问题。见stackoverflow.com/questions/5944332/…
标签: django postgis ubuntu-11.10 geodjango postgresql-9.1