问题
I'm working on a GeoDjango application and am using Heroku (with a Heroku-16 stack) as my platform.
I am following the instructions found here, which specify the following:
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.
I have set the env variables in Heroku:
However, I have found that this isn't making a difference when it's time to deploy:
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.
Here's my 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
The only anomaly I have here is that I'm using Django 1.11.5 instead of what the default was with Heroku's Django project template, which is 1.11.1. This was to fix a problem that kept the project from working that was patched.
Procfile is:
web: gunicorn tagging_tracker_backend.wsgi
runtime.txt is:
python-3.6.2
The Github repo is at this link.
回答1:
Heroku documentation says that:
Note: This feature(BUILD_WITH_GEO_LIBRARIES) is only known to work well on cedar-14. We are working to ensure that it works properly on heroku-16, slowly.
https://devcenter.heroku.com/articles/python-c-deps#geodjango-application-libraries
In order to use cedar-14:
$ heroku stack:set cedar-14 --app YOUR_APP
回答2:
1) Change your Django settings.py:
Before:
GDAL_LIBRARY_PATH = os.getenv('GDAL_LIBRARY_PATH')
GEOS_LIBRARY_PATH = os.getenv('GEOS_LIBRARY_PATH')
Now:
GDAL_LIBRARY_PATH = os.environ.get('GDAL_LIBRARY_PATH')
GEOS_LIBRARY_PATH = os.environ.get('GEOS_LIBRARY_PATH')
2) Set config var:
$ heroku config:set BUILD_WITH_GEO_LIBRARIES=1
3) Change Heroku's stack:
$ heroku stack:set cedar-14
回答3:
For latest version we can use
heroku stack:set cedar-18 --app YOUR_APP
来源:https://stackoverflow.com/questions/46383875/heroku-geodjango-issues-with-missing-gdal-and-possibly-geos