Heroku-22栈升级后Django无法找到正确GDAL版本求助
更新
将Django升级到3.2版本并未解决错误。 我收到了相同的错误提示,只是涉及的版本有所不同
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.
我找到了一个讨论线程,其中似乎有类似问题,但未得到解决。我按照该线程的建议,在settings.py中添加了以下内容:
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')
不过我仍然收到错误,是另一个不同的错误(或许离解决更近了?)
OSError: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/gis/gdal: cannot open shared object file: No such file or directory
有趣的是,它似乎在寻找python3.7,但之前明明使用的是正确的python3.10。我检查过项目代码,没有任何地方指定了python3.7
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)
原帖内容
我正尝试将我的Django Web应用从Heroku-18栈升级到Heroku-22栈。为了使用新栈,我必须将Python从3.7.2升级到3.10.8。
根据我在Stack Overflow及其他网络资源中了解到的信息,我已经按照Heroku上Django应用的正确方式安装了GDAL/GIS,即使用buildpack并将其排在buildpack列表的第一位:
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
我本以为升级不会有问题,但现在不知为何无法找到GDAL库。以下是已安装的版本:
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
以下是我遇到的错误。
请注意,它并未寻找已安装的gdal2.4.0,不过它在寻找gdal,我本以为这个安装包能覆盖该需求。
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.
虽然某个问题的答案指出无需设置GDAL_LIBRARY_PATH变量,但我认为可以尝试设置该变量。不过我不确定GDAL的安装路径,因为如果不解决这个问题,构建就会失败。
如果有人知道解决方案,将非常感谢!!!
此前参考的资料:
- Django with GDAL部署到Heroku时抛出错误
- Heroku上缺失GDAL
- Python的build_with_geo_libraries旧特性已不再受支持
完整错误追踪:
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
内容的提问来源于stack exchange,提问作者Sasha Ahrestani
相关产品推荐
相关产品推荐

