在 Django 中为 ubuntu 11.10 设置 Postgresql 9.1 数据库

Posted

技术标签:

【中文标题】在 Django 中为 ubuntu 11.10 设置 Postgresql 9.1 数据库【英文标题】:setting up Postgresql 9.1 database in Django for ubuntu 11.10 【发布时间】:2012-03-10 16:08:46 【问题描述】:

我正在尝试在 Django 1.3 中配置 Postgresql 9.1 。 注意:我在 Ubuntu 11.10 (oneric) 中执行此操作。我还安装了 postgis 1.5 以使用 Postgresql 9.1

据我所知,我已安装所需的所有依赖项。 我还阅读了 this 博客的说明。

关于执行以下操作:

python manage.py syncdb

我收到此错误堆栈。

Traceback (most recent call last):
  File "manage.py", line 23, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/south/management/commands/__init__.py", line 10, in <module>
    import django.template.loaders.app_directories
  File "/usr/local/lib/python2.7/dist-packages/django/template/loaders/app_directories.py", line 23, in <module>
    raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
django.core.exceptions.ImproperlyConfigured: ImportError ProjectName.ModuleName: No module named postgresql.operations

在 local_settings.py 中,我将引擎名称设置为 'django.db.backends.postgresql_psycopg2'。

但是在参考this 之后,我将引擎名称设置为 'django.contrib.gis.db.backends.postgis' ,我得到以下错误堆栈:

    Traceback (most recent call last):
  File "manage.py", line 23, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/south/management/commands/__init__.py", line 10, in <module>
    import django.template.loaders.app_directories
  File "/usr/local/lib/python2.7/dist-packages/django/template/loaders/app_directories.py", line 21, in <module>
    mod = import_module(app)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/jigish/jigbox/dev/mangrove/datawinners/datawinners/../datawinners/accountmanagement/__init__.py", line 3, in <module>
    from datawinners.accountmanagement.post_registration_events import ngo_user_created
  File "/home/jigish/jigbox/dev/mangrove/datawinners/datawinners/../datawinners/accountmanagement/post_registration_events.py", line 3, in <module>
    from datawinners.accountmanagement.models import NGOUserProfile
  File "/home/jigish/jigbox/dev/mangrove/datawinners/datawinners/../datawinners/accountmanagement/models.py", line 5, in <module>
    from django.db import models
  File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 78, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 51, 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 postgresql.operations

我什至确保,我已经安装了 postgis (Postgresql-9.1-postgis)。

我哪里错了?我错过了什么? 这些是我早期使用 Python、Django、Postgresql 和 Postgis 的经历。 请指出网络上任何相关的有用链接。我尝试了谷歌搜索,但到目前为止没有成功。

感谢和问候

【问题讨论】:

“据我所知,我已经安装了所有需要的依赖项。”。请详细说明。你安装了 psycopg2 吗?您可以发布您已安装的软件包列表(apt 和 python)吗? TYIA 我的问题中提到的链接中已经提到了这一点。还在重复我自己。 gdal-bin binutils libgeos-3.2.2 libgeos-c1 libgeos-dev libgdal1-1.8.0 libgdal1-dev libxml2 libxml2-dev libxml2-dev proj psycopg2 == 2.4.1. 你在说什么清单?我对你 psycopg2 安装的问题呢? Postgresql 9.1 Postgresql-9.1-postgis django 1.3 您是否将 django.contrib.gis 添加到 INSTALLED_APPS 中? 【参考方案1】:

我遇到了同样的问题。错误的常见来源似乎是 psycopg2 配置不正确。

我发现这些帖子很有帮助:

Unable to syncdb in GeoDjango App

Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found

banging my head on setting up and running geodjango

【讨论】:

【参考方案2】:

您应该使用“django.contrib.gis.db.backends.postgis”作为后端,这是肯定的;根据the official installation guide.

我认为您可以在那里提交文档错误,因为文档没有提到 ubuntu 11.10。

【讨论】:

我已按照安装指南进行操作。但是,安装指南适用于 Ubuntu 10.10 及更低版本的用户。我还想让你知道,在 Ubuntu 11.04 之前,正常的安装步骤都可以正常工作。因此我在 11.10 试了一下。

以上是关于在 Django 中为 ubuntu 11.10 设置 Postgresql 9.1 数据库的主要内容,如果未能解决你的问题,请参考以下文章

在VirtualBox4.1.10安装了Ubuntu 11.10,怎么实现Ubuntu 11.10与主机上的文件共享?

ubuntu11.10怎样关机啊

在 ubuntu 11.10 上安装 GCC 4.3.4 时出错

无法使用普通 Ubuntu Linux 用户访问 Django 中的 PostgreSQL 数据库

rvm,ubuntu 11.10 gem 阻止服务器启动

如何在Ubuntu 11.10 下安装KScope