简体   繁体   中英

Heroku Django: Looking for wrong GDAL version on new Heroku-22 Stack

UPDATE

Upgrading Django to version 3.2 has not fixed the error. I am receiving the same error message, just with different versions

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal3.1.0", "gdal3.0.0", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

I found this one thread where a discussion was being had I think with a similar issue, however it ended before it was resolved. I added this to my settings.py which was mentioned in that thread:

GEOS_LIBRARY_PATH = '/app/.heroku/vendor/lib/libgeos_c.so' if os.environ.get('ENV') == 'HEROKU' else os.getenv('GEOS_LIBRARY_PATH')
GDAL_LIBRARY_PATH = '/app/.heroku/vendor/lib/libgdal.so' if os.environ.get('ENV') == 'HEROKU' else os.getenv('GDAL_LIBRARY_PATH')

I am receiving an error still though, a different one (maybe getting closer?)

OSError: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/gis/gdal: cannot open shared object file: No such file or directory

It's interesting because it seems to be looking for python3.7 but right before it's using the correct python3.10. I checked, there is no trace of a python3.7 specificied anywhere in my project code

from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/gis/gdal/libgdal.py", line 50, in <module>
lgdal = CDLL(lib_path)
File "/app/.heroku/python/lib/python3.10/ctypes/__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)

ORIGINAL POST

I am trying to upgrade from the Heroku-18 to Heroku-22 stack, for my Django web app. In order to use the new stack, I had to upgrade from Python 3.7.2 to Python 3.10.8.

From what I've seen on Stack Overflow so far and other sources on the inte.net, I have already been installing GDAL/GIS the correct way for a Django app on Heroku. Which is to use a buildpack and have it ordered first in the list of buildpacks:

remote: Building source:
remote: 
remote: -----> Building on the Heroku-22 stack
remote: -----> Using buildpacks:
remote:        1. https://github.com/heroku/heroku-geo-buildpack.git
remote:        2. heroku/python

I expected no issues on the upgrade, but now for some reason it's having trouble finding GDAL. These are the versions that are being installed:

remote: -----> Geo Packages (GDAL/GEOS/PROJ) app detected
remote: -----> Installing GDAL-2.4.0
remote: -----> Installing GEOS-3.7.2
remote: -----> Installing PROJ-5.2.0

And here is the error I'm getting. Notice that it is not looking for gdal2.4.0 , which is what's installed. However, it is looking for gdal which I'd hope would be covered by this install.

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.

While the answer to this question states not to set the GDAL_LIBRARY_PATH variable, I think one potential solution would be to set that anyway. However, I'm not sure where GDAL is being installed, as it isn't able to be installed at all without the build failing and an error occuring.

If anyone knows a solution, that would be super helpful. Thank you so much!!!

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Sources looked at before:

Full error trace:

remote: -----> Building on the Heroku-22 stack
remote: -----> Using buildpacks:
remote:        1. https://github.com/heroku/heroku-geo-buildpack.git
remote:        2. heroku/python
remote: -----> Geo Packages (GDAL/GEOS/PROJ) app detected
remote: -----> Installing GDAL-2.4.0
remote: -----> Installing GEOS-3.7.2
remote: -----> Installing PROJ-5.2.0
remote: -----> Python app detected
remote: -----> Using Python version specified in runtime.txt
remote: -----> Stack has changed from heroku-18 to heroku-22, clearing cache
remote: -----> Installing python-3.10.8
remote: -----> Installing pip 22.3.1, setuptools 63.4.3 and wheel 0.37.1
remote: -----> Installing dependencies with Pipenv 2020.11.15
remote:        Installing dependencies from Pipfile.lock (9f21b7)...
remote: -----> Installing SQLite3
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "/tmp/build_5b1145a7/manage.py", line 15, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 357, in execute
remote:            django.setup()
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
remote:            apps.populate(settings.INSTALLED_APPS)
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/apps/registry.py", line 112, in populate
remote:            app_config.import_models()
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/apps/config.py", line 198, in import_models
remote:            self.models_module = import_module(models_module_name)
remote:          File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "<frozen importlib._bootstrap>", line 1050, in _gcd_impor
remote:          File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
remote:          File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
remote:          File "<frozen importlib._bootstrap_external>", line 883, in exec_module
remote:          File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
remote:          File "/tmp/build_5b1145a7/*****/models.py", line 6, in <module
remote:            from *****.models import *****, *****
remote:          File "/tmp/build_5b1145a7/*****/models.py", line 4, in <module>
remote:            from .models_functions import (is_url, is_state, attempt_str2bool, is_choice, are_choices, choice_name, display_range)
remote:          File "/tmp/build_5b1145a7/*****/models_functions.py", line 7, in <module>
remote:            from django.contrib.gis.geos import Point
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/gis/geos/__init__.py", line 5, in <module>
remote:            from .collections import (  # NOQA
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/gis/geos/collections.py", line 9, in <module>
remote:            from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/gis/geos/geometry.py", line 8, in <module>
remote:            from django.contrib.gis import gdal
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
remote:            from django.contrib.gis.gdal.datasource import DataSource
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/gis/gdal/datasource.py", line 39, in <module>
remote:            from django.contrib.gis.gdal.driver import Driver
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
remote:            from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
remote:            from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
remote:          File "/app/.heroku/python/lib/python3.10/site-packages/django/contrib/gis/gdal/libgdal.py", line 40, in <module>
remote:            raise ImproperlyConfigured(
remote:        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.
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'
remote:        See traceback above for details.
remote: 
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote: 
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote: 
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed

What version of Django are you using? I suspect it's quite old.

The list of supported versions of GDAL for Django 2.1 matches the list in your error message:

  • 2.2
  • 2.1
  • 2.0
  • 1.11
  • 1.10
  • 1.9

You'll have to upgrade to at least Django 3.0 to get support for GDAL 2.4 , but even that version is well beyond its extended support period , which ended April 6, 2021.

I suggest you upgrade to at least Django 3.2, the oldest actively supported version. It's an LTS release and should continue to receive support until April, 2024.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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