python - Heroku GeoDjango 缺少 GDAL(可能还有 GEOS)的问题

标签 python django heroku gdal geodjango

我正在开发 GeoDjango 应用程序并使用 Heroku(带有 Heroku-16 堆栈)作为我的平台。

我正在按照找到的说明进行操作 here ,其中指定以下内容:

If your application requires geo libraries, experimental support for a handful of these libraries are available:

  • GDAL v2.2.1 (v1.11.5 for cedar-14)
  • Geos v3.6.2 (v3.4.2 for cedar-14)
  • Proj v4.9.3 (v4.8.0 for cedar-14)

To make these libraries available to your application, simply set the BUILD_WITH_GEO_LIBRARIES environment variable:

$ heroku config:set BUILD_WITH_GEO_LIBRARIES=1

During your next build, these libraries will be downloaded and installed. In your Django settings.py, also add the following:

import dj_database_url
DATABASES['default'] = dj_database_url.config()
DATABASES['default']['ENGINE'] = 
'django.contrib.gis.db.backends.postgis'

GDAL_LIBRARY_PATH = os.getenv('GDAL_LIBRARY_PATH')
GEOS_LIBRARY_PATH = os.getenv('GEOS_LIBRARY_PATH')

This will ensure that Django can find the GEOS libraries that are installed.

我已经在 Heroku 中设置了环境变量:

image

但是,我发现在部署时这并没有什么不同:

2017-09-23T19:29:55.142378+00:00 app[web.1]:     % '", "'.join(lib_names)
2017-09-23T19:29:55.142414+00:00 app[web.1]: 
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL 
library (tried "gdal", "GDAL", "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.

这是我的 requirements.txt:

dj-database-url==0.4.1
Django==1.11.5
gunicorn==19.6.0
psycopg2==2.6.2
pytz==2017.2
whitenoise==3.2

这里唯一的异常是我使用的是 Django 1.11.5,而不是 Heroku 的 Django 项目模板的默认版本,即 1.11.1。这是为了解决使项目无法正常工作的问题,该问题已打补丁。

配置文件是:

web: gunicorn tagging_tracker_backend.wsgi

runtime.txt 是:

python-3.6.2

Github 存储库位于 this链接。

最佳答案

Heroku 文档说:

注意:此功能 (BUILD_WITH_GEO_LIBRARIES) 仅在 cedar-14 上运行良好。我们正在努力确保它在 heroku-16 上正常运行,速度很慢。

https://devcenter.heroku.com/articles/python-c-deps#geodjango-application-libraries

为了使用 cedar-14:

$ heroku stack:set cedar-14 --app YOUR_APP 

关于python - Heroku GeoDjango 缺少 GDAL(可能还有 GEOS)的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46383875/

相关文章:

python - 获取字典的父子关系

python - Pandas 数据框创建新列,指示其他列中的重叠值

Python最大递归,关于sys.setrecursionlimit()的问题

ruby-on-rails - 从另一个本地分支推送到 heroku

python - 为什么 whitenoise 在 Heroku 上的默认 Django 项目中崩溃?

python - 如何为python指定 native 库搜索路径

django - 为什么 django 为外键生成选择框很慢?

python - 在 Django 中使用交互式控件制作 Bokeh 图

mysql - Django 双内连接与 mysql 慢

android - 安全 API 访问 : best strategy to secure readonly rails api for android client