我正在尝试使用AWS EC2上的服务器代码和RDS上的Spatial DB Postgis构建应用程序。我可以使用命令行从EC2访问Postgres:
psql --host=mydbpostgres.qazwsxedcrfv.us-west-1.rds.amazonaws.com --port=5432 --username=ec2 --password --dbname=mydb
mydb=>
我在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',
}
}
但是当我运行迁移时,它会给出我的错误:
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
看起来我在EC2上遗漏了一些postgis库。我的问题是,我是否需要在ec2上安装postgis实例,以便我的服务器可以找到所有必需的库?或者我如何让我的服务器在RDS上查找lib?
非常感谢!
答案 0 :(得分:3)
看起来你只是错过了&#34; geos&#34;图书馆。如果您正在运行Amazon Linux,那么安装就像yum install geos
一样简单。该库提供文件:/usr/lib/libgeos_c.so.1