简体   繁体   English

Django与AWS EC2上的GeoDjango,RDS上的Postgres Postgis

[英]Django with GeoDjango on AWS EC2, Postgres Postgis on RDS

I'm trying to build an application with server code on AWS EC2 and the Spatial DB Postgis on RDS. 我正在尝试使用AWS EC2上的服务器代码和RDS上的Spatial DB Postgis构建应用程序。 I can access the Postgres from EC2 using command line: 我可以使用命令行从EC2访问Postgres:

psql --host=mydbpostgres.qazwsxedcrfv.us-west-1.rds.amazonaws.com --port=5432 --username=ec2 --password --dbname=mydb
mydb=>

I use GeoDjango on the EC2, and this is the setting for my DB: 我在EC2上使用GeoDjango,这是我的数据库的设置:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydb',
    'USER': 'ec2',
    'PASSWORD': 'password',
    'HOST': 'mydbpostgres.qazwsxedcrfv.us-west-1.rds.amazonaws.com',
    'PORT': '5432',
    }
}

But when I run migration, it gives my error like this: 但是,当我运行迁移时,它会给出如下错误:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 280, in execute
    translation.activate('en-us')
  File "/usr/lib/python2.6/site-packages/django/utils/translation/__init__.py", line 130, in activate
    return _trans.activate(language)
  File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/usr/lib/python2.6/site-packages/django/contrib/admin/__init__.py", line 6, in <module>
    from django.contrib.admin.sites import AdminSite, site
  File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 4, in <module>
    from django.contrib.admin.forms import AdminAuthenticationForm
  File "/usr/lib/python2.6/site-packages/django/contrib/admin/forms.py", line 6, in <module>
    from django.contrib.auth.forms import AuthenticationForm
  File "/usr/lib/python2.6/site-packages/django/contrib/auth/forms.py", line 17, in <module>
    from django.contrib.auth.models import User
  File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 48, in <module>
    class Permission(models.Model):
  File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 96, in __new__
    new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 264, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/lib/python2.6/site-packages/django/db/models/options.py", line 124, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 198, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 113, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/usr/lib/python2.6/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 5, in <module>
    from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
  File "/usr/lib/python2.6/site-packages/django/contrib/gis/db/backends/postgis/operations.py", line 8, in <module>
    from django.contrib.gis.geometry.backend import Geometry
  File "/usr/lib/python2.6/site-packages/django/contrib/gis/geometry/backend/__init__.py", line 8, in <module>
    module = import_module('django.contrib.gis.geometry.backend.%s' % geom_backend)
  File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/usr/lib/python2.6/site-packages/django/contrib/gis/geometry/backend/geos.py", line 1, in <module>
    from django.contrib.gis.geos import (
  File "/usr/lib/python2.6/site-packages/django/contrib/gis/geos/__init__.py", line 7, in <module>
    from .libgeos import geos_version, geos_version_info, GEOS_PREPARE
  File "/usr/lib/python2.6/site-packages/django/contrib/gis/geos/libgeos.py", line 58, in <module>
    lgeos = CDLL(lib_path)
      File "/usr/lib64/python2.6/ctypes/__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libgeos_c.so.1: cannot open shared object file: No such file or directory

It looks like I'm missing some libraries of postgis on my EC2. 好像我的EC2上缺少一些Postgis库。 My question is, do I need to install a postgis instance on my ec2 so that my server can find all that necessary libs? 我的问题是,我是否需要在ec2上安装postgis实例,以便服务器可以找到所有必需的库? Or how can I make my server to look for the libs on the RDS? 或者如何使我的服务器在RDS上查找库?

Thanks very much! 非常感谢!

It looks like you're just missing the "geos" library. 看来您只是缺少“ geos”库。 If you're running Amazon Linux, installing that is as simple as yum install geos . 如果您正在运行Amazon Linux,则安装就像yum install geos一样简单。 That library provides the file: /usr/lib/libgeos_c.so.1 该库提供文件:/usr/lib/libgeos_c.so.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM