如何修复django.core.exceptions.ImproperlyConfigured:在GAE上找不到GDAL库

时间:2019-03-29 01:00:32

标签: django postgresql google-app-engine postgis

我想执行查找附近位置的功能。这是关于餐馆的,所以我有我的位置(经度,纬度),我需要在给定半径内找到最近的餐馆。

我正在使用django 2.1.7和postgres 11.2。对于地理定位和地理空间查询,可以使用postgis扩展。

在我的计算机上,它可以正常工作。

这是我的代码段:

# [START db_setup]
if os.getenv('GAE_APPLICATION', None):
    # Running on production App Engine, so connect to Google Cloud SQL using
    # the unix socket at /cloudsql/<your-cloudsql-connection string>
    DATABASES = {
        'default': {
            'ENGINE': 'django.contrib.gis.db.backends.postgis',
            'HOST': '/cloudsql/blog:us-central1:mb',
            'USER': 'user',
            'PASSWORD': 'password',
            'NAME': 'blog',
            'PORT': '5432'
        }
    }
else:
    # Running locally so connect to either a local MySQL instance or connect to
    # Cloud SQL via the proxy. To start the proxy via command line:
    #
    #     $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
    #
    # See https://cloud.google.com/sql/docs/mysql-connect-proxy
    DATABASES = {
        'default': {
            'ENGINE': 'django.contrib.gis.db.backends.postgis',
            'HOST': '127.0.0.1',
            'USER': 'user',
            'NAME': 'db_name',
            'PORT': '5432',
        }
    }
# [END db_setup]

数据库的配置为:

gcloud app logs tail -s default

部署在GAE实例上运行,而postgres在Cloud SQL实例上。

当我进行部署时,页面会抛出502 Bad Gateway,命令2019-03-29 00:52:41 default[20190328t173044] Traceback (most recent call last): File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process super(ThreadWorker, self).init_process() File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process self.load_wsgi() File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi self.wsgi = self.app.wsgi() File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load return self.load_wsgiapp() File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp return util.import_app(self.app_uri) File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app __import__(module) File "/srv/main.py", line 1, in <module> from marcobetetaapi.wsgi import application File "/srv/marcobetetaapi/wsgi.py", line 16, in <module> application = get_wsgi_application() File "/env/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application django.setup(set_prefix=False) File "/env/lib/python3.7/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/env/lib/python3.7/site-packages/django/apps/registry.py", line 112, in populate app_config.import_models() File "/env/lib/python3.7/site-packages/django/apps/config.py", line 198, in import_models self.models_module = import_module(models_module_name) File "/opt/python3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/srv/recommendations/models.py", line 1, in <module> from django.contrib.gis.db import models File "/env/lib/python3.7/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module> import django.contrib.gis.db.models.functions # NOQA File "/env/lib/python3.7/site-packages/django/contrib/gis/db/models/functions.py", line 4, in <module> from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField File "/env/lib/python3.7/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module> from django.contrib.gis import forms, gdal File "/env/lib/python3.7/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module> from .fields import ( # NOQA File "/env/lib/python3.7/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module> from django.contrib.gis.geos import GEOSException, GEOSGeometry File "/env/lib/python3.7/site-packages/django/contrib/gis/geos/__init__.py", line 5, in <module> from .collections import ( # NOQA File "/env/lib/python3.7/site-packages/django/contrib/gis/geos/collections.py", line 9, in <module> from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin File "/env/lib/python3.7/site-packages/django/contrib/gis/geos/geometry.py", line 8, in <module> from django.contrib.gis import gdal File "/env/lib/python3.7/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module> from django.contrib.gis.gdal.datasource import DataSource File "/env/lib/python3.7/site-packages/django/contrib/gis/gdal/datasource.py", line 39, in <module> from django.contrib.gis.gdal.driver import Driver File "/env/lib/python3.7/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module> from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi File "/env/lib/python3.7/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module> from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal File "/env/lib/python3.7/site-packages/django/contrib/gis/gdal/libgdal.py", line 43, in <module> % '", "'.join(lib_names) django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0", "gdal1.10.0", "gdal1.9.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.表示:

{{1}}

我正在阅读有关同一问题的预览问题,他们说GAE不支持GDAL库,但是这些问题来自几年前。我想知道是否知道它的支持,或者我可以通过使用django和postgres进行更改以使其再次起作用。

0 个答案:

没有答案