在 Heroku 上部署时带有 GDAL 的 Django 抛出错误
Django with GDAL throwing error when deploying on Heroku
当我使用 Heroku 部署我的 Django 应用程序时,GDAL 似乎出现了一些问题。当我 运行 heroku logs --tail
我得到以下信息:
[...]
2022-01-14T11:20:56.792392+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 6, in <module>
2022-01-14T11:20:56.792393+00:00 app[web.1]: from .features import DatabaseFeatures
2022-01-14T11:20:56.792393+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/features.py", line 1, in <module>
2022-01-14T11:20:56.792394+00:00 app[web.1]: from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
2022-01-14T11:20:56.792394+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/base/features.py", line 3, in <module>
2022-01-14T11:20:56.792394+00:00 app[web.1]: from django.contrib.gis.db import models
2022-01-14T11:20:56.792395+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
2022-01-14T11:20:56.792395+00:00 app[web.1]: import django.contrib.gis.db.models.functions # NOQA
2022-01-14T11:20:56.792395+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
2022-01-14T11:20:56.792396+00:00 app[web.1]: from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
2022-01-14T11:20:56.792401+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
2022-01-14T11:20:56.792401+00:00 app[web.1]: from django.contrib.gis import forms, gdal
2022-01-14T11:20:56.792402+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
2022-01-14T11:20:56.792402+00:00 app[web.1]: from .fields import ( # NOQA
2022-01-14T11:20:56.792402+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
2022-01-14T11:20:56.792402+00:00 app[web.1]: from django.contrib.gis.gdal import GDALException
2022-01-14T11:20:56.792403+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
2022-01-14T11:20:56.792406+00:00 app[web.1]: from django.contrib.gis.gdal.datasource import DataSource
2022-01-14T11:20:56.792407+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/datasource.py", line 40, in <module>
2022-01-14T11:20:56.792407+00:00 app[web.1]: from django.contrib.gis.gdal.driver import Driver
2022-01-14T11:20:56.792407+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
2022-01-14T11:20:56.792407+00:00 app[web.1]: from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
2022-01-14T11:20:56.792408+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
2022-01-14T11:20:56.792408+00:00 app[web.1]: from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
2022-01-14T11:20:56.792408+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/libgdal.py", line 53, in <module>
2022-01-14T11:20:56.792409+00:00 app[web.1]: lgdal = CDLL(lib_path)
2022-01-14T11:20:56.792409+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/ctypes/__init__.py", line 374, in __init__
2022-01-14T11:20:56.792409+00:00 app[web.1]: self._handle = _dlopen(self._name, mode)
2022-01-14T11:20:56.792409+00:00 app[web.1]: OSError: /opt/homebrew/opt/gdal/lib/libgdal.dylib: cannot open shared object file: No such file or directory
2022-01-14T11:20:56.792410+00:00 app[web.1]: [2022-01-14 11:20:56 +0000] [10] [INFO] Worker exiting (pid: 10)
2022-01-14T11:20:56.895552+00:00 app[web.1]: [2022-01-14 11:20:56 +0000] [4] [WARNING] Worker with pid 10 was terminated due to signal 15
2022-01-14T11:20:56.993856+00:00 app[web.1]: [2022-01-14 11:20:56 +0000] [4] [INFO] Shutting down: Master
2022-01-14T11:20:56.993930+00:00 app[web.1]: [2022-01-14 11:20:56 +0000] [4] [INFO] Reason: Worker failed to boot.
2022-01-14T11:20:57.168821+00:00 heroku[web.1]: Process exited with status 3
[...]
我正在使用启用了 postgis
的 PostgreSQL 数据库(它是一个地理定位应用程序)。
我已经安装了这个 buildpack,我的 requirements.txt
文件中有 GDAL==2.4.0
(与 buildpack 似乎安装的版本一致)。
我对 dylibs
的理解是它们是 MACOS 文件类型 - 因此 Heroku
指向我的本地机器 GDAL
而不是 Heroku dyno
,我'我对这一切还很陌生,但我相信我需要弄清楚为什么会发生这种情况以及如何更改 Heroku 搜索 GDAL
.
的位置
Requirements.txt:
asgiref==3.4.1
beautifulsoup4==4.10.0
bs4==0.0.1
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.10
cryptography==36.0.1
defusedxml==0.7.1
dj-database-url==0.5.0
Django==4.0.1
django-allauth==0.47.0
django-bootstrap-modal-forms==2.2.0
django-heroku==0.3.1
django-on-heroku==1.1.2
django-widget-tweaks==1.4.11
djangorestframework==3.13.1
GDAL==2.4.0
gunicorn==20.1.0
idna==3.3
oauthlib==3.1.1
psycopg2==2.9.3
psycopg2-binary==2.9.3
pycparser==2.21
PyJWT==2.3.0
python3-openid==3.2.0
pytz==2021.3
requests==2.27.1
requests-oauthlib==1.3.0
soupsieve==2.3.1
sqlparse==0.4.2
urllib3==1.26.8
whitenoise==5.3.0
当我使用 Heroku 部署我的 Django 应用程序时,GDAL 似乎出现了一些问题。当我 运行 heroku logs --tail
我得到以下信息:
[...]
2022-01-14T11:20:56.792392+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 6, in <module>
2022-01-14T11:20:56.792393+00:00 app[web.1]: from .features import DatabaseFeatures
2022-01-14T11:20:56.792393+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/features.py", line 1, in <module>
2022-01-14T11:20:56.792394+00:00 app[web.1]: from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
2022-01-14T11:20:56.792394+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/base/features.py", line 3, in <module>
2022-01-14T11:20:56.792394+00:00 app[web.1]: from django.contrib.gis.db import models
2022-01-14T11:20:56.792395+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
2022-01-14T11:20:56.792395+00:00 app[web.1]: import django.contrib.gis.db.models.functions # NOQA
2022-01-14T11:20:56.792395+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
2022-01-14T11:20:56.792396+00:00 app[web.1]: from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
2022-01-14T11:20:56.792401+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
2022-01-14T11:20:56.792401+00:00 app[web.1]: from django.contrib.gis import forms, gdal
2022-01-14T11:20:56.792402+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
2022-01-14T11:20:56.792402+00:00 app[web.1]: from .fields import ( # NOQA
2022-01-14T11:20:56.792402+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
2022-01-14T11:20:56.792402+00:00 app[web.1]: from django.contrib.gis.gdal import GDALException
2022-01-14T11:20:56.792403+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
2022-01-14T11:20:56.792406+00:00 app[web.1]: from django.contrib.gis.gdal.datasource import DataSource
2022-01-14T11:20:56.792407+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/datasource.py", line 40, in <module>
2022-01-14T11:20:56.792407+00:00 app[web.1]: from django.contrib.gis.gdal.driver import Driver
2022-01-14T11:20:56.792407+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
2022-01-14T11:20:56.792407+00:00 app[web.1]: from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
2022-01-14T11:20:56.792408+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
2022-01-14T11:20:56.792408+00:00 app[web.1]: from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
2022-01-14T11:20:56.792408+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/gdal/libgdal.py", line 53, in <module>
2022-01-14T11:20:56.792409+00:00 app[web.1]: lgdal = CDLL(lib_path)
2022-01-14T11:20:56.792409+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/ctypes/__init__.py", line 374, in __init__
2022-01-14T11:20:56.792409+00:00 app[web.1]: self._handle = _dlopen(self._name, mode)
2022-01-14T11:20:56.792409+00:00 app[web.1]: OSError: /opt/homebrew/opt/gdal/lib/libgdal.dylib: cannot open shared object file: No such file or directory
2022-01-14T11:20:56.792410+00:00 app[web.1]: [2022-01-14 11:20:56 +0000] [10] [INFO] Worker exiting (pid: 10)
2022-01-14T11:20:56.895552+00:00 app[web.1]: [2022-01-14 11:20:56 +0000] [4] [WARNING] Worker with pid 10 was terminated due to signal 15
2022-01-14T11:20:56.993856+00:00 app[web.1]: [2022-01-14 11:20:56 +0000] [4] [INFO] Shutting down: Master
2022-01-14T11:20:56.993930+00:00 app[web.1]: [2022-01-14 11:20:56 +0000] [4] [INFO] Reason: Worker failed to boot.
2022-01-14T11:20:57.168821+00:00 heroku[web.1]: Process exited with status 3
[...]
我正在使用启用了 postgis
的 PostgreSQL 数据库(它是一个地理定位应用程序)。
我已经安装了这个 buildpack,我的 requirements.txt
文件中有 GDAL==2.4.0
(与 buildpack 似乎安装的版本一致)。
我对 dylibs
的理解是它们是 MACOS 文件类型 - 因此 Heroku
指向我的本地机器 GDAL
而不是 Heroku dyno
,我'我对这一切还很陌生,但我相信我需要弄清楚为什么会发生这种情况以及如何更改 Heroku 搜索 GDAL
.
Requirements.txt:
asgiref==3.4.1
beautifulsoup4==4.10.0
bs4==0.0.1
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.10
cryptography==36.0.1
defusedxml==0.7.1
dj-database-url==0.5.0
Django==4.0.1
django-allauth==0.47.0
django-bootstrap-modal-forms==2.2.0
django-heroku==0.3.1
django-on-heroku==1.1.2
django-widget-tweaks==1.4.11
djangorestframework==3.13.1
GDAL==2.4.0
gunicorn==20.1.0
idna==3.3
oauthlib==3.1.1
psycopg2==2.9.3
psycopg2-binary==2.9.3
pycparser==2.21
PyJWT==2.3.0
python3-openid==3.2.0
pytz==2021.3
requests==2.27.1
requests-oauthlib==1.3.0
soupsieve==2.3.1
sqlparse==0.4.2
urllib3==1.26.8
whitenoise==5.3.0