OSError: libgdal.dylib: cannot open file
OSError: libgdal.dylib: cannot open file
问题是:由于 OSError: /opt/homebrew/Cellar/gdal/3.3.0_2/lib/libgdal.dylib: cannot open shared object file: No such file or directory
,Docker 没有正确 运行。
我当前的任务只是将 GeoDjango 添加到我现有的 Django dockerized 项目中,使用 PostGIS 数据库。我用 postgis/postgis.
安装了 postgis 图像
我猜是因为 gdal 安装不正确导致出错。我用 Homebrew 安装了 gdal。老实说,如果我使用 Docker.
,我不明白为什么我的机器上需要 gdal
现在我在 MacBook Air(M1,2020)和所有软件包的最新版本上使用 Big Sur OS。
我找到了很多类似案例的描述,但和我的不完全一样,原因也不一样。
我想弄清楚我遇到的是什么问题,为什么会出现,以及如何解决。
非常感谢任何帮助。
详情:
如果我这样做 docker compose up
,我会看到一个正常的过程开始,然后是一个错误:
(venv) [computer_name]@G-MacBook-Air-2 [project_name] % docker compose up
[+] Running 2/0
⠿ Container 64a949117135_[project_name]_db_1 Created 0.0s
⠿ Container 0e8ee44abd93_[project_name]_web_1 Created 0.0s
Attaching to 0e8ee44abd93_[project_name]_web_1, 64a949117135_[project_name]_db_1
64a949117135_[project_name]_db_1 |
64a949117135_[project_name]_db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
64a949117135_[project_name]_db_1 |
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.354 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.358 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.358 UTC [1] LOG: listening on IPv6 address "::", port 5432
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.365 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.386 UTC [62] LOG: database system shutdown was interrupted; last known up at 2021-06-25 11:05:06 UTC
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.549 UTC [62] LOG: database system was not properly shut down; automatic recovery in progress
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.555 UTC [62] LOG: redo starts at 0/1F45190
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.556 UTC [62] LOG: invalid record length at 0/1F451C8: wanted 24, got 0
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.556 UTC [62] LOG: redo done at 0/1F45190
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.614 UTC [1] LOG: database system is ready to accept connections
0e8ee44abd93_[project_name]_web_1 | Exception in thread django-main-thread:
0e8ee44abd93_[project_name]_web_1 | Traceback (most recent call last):
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
0e8ee44abd93_[project_name]_web_1 | self.run()
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/threading.py", line 892, in run
0e8ee44abd93_[project_name]_web_1 | self._target(*self._args, **self._kwargs)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
0e8ee44abd93_[project_name]_web_1 | fn(*args, **kwargs)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
0e8ee44abd93_[project_name]_web_1 | autoreload.raise_last_exception()
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
0e8ee44abd93_[project_name]_web_1 | raise _exception[1]
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute
0e8ee44abd93_[project_name]_web_1 | autoreload.check_errors(django.setup)()
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
0e8ee44abd93_[project_name]_web_1 | fn(*args, **kwargs)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
0e8ee44abd93_[project_name]_web_1 | apps.populate(settings.INSTALLED_APPS)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
0e8ee44abd93_[project_name]_web_1 | app_config.import_models()
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 211, in import_models
0e8ee44abd93_[project_name]_web_1 | self.models_module = import_module(models_module_name)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
0e8ee44abd93_[project_name]_web_1 | return _bootstrap._gcd_import(name[level:], package, level)
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap_external>", line 855, in exec_module
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/models.py", line 2, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
0e8ee44abd93_[project_name]_web_1 | class AbstractBaseUser(models.Model):
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 122, in __new__
0e8ee44abd93_[project_name]_web_1 | new_class.add_to_class('_meta', Options(meta, app_label))
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class
0e8ee44abd93_[project_name]_web_1 | value.contribute_to_class(cls, name)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/models/options.py", line 206, in contribute_to_class
0e8ee44abd93_[project_name]_web_1 | self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/__init__.py", line 28, in __getattr__
0e8ee44abd93_[project_name]_web_1 | return getattr(connections[DEFAULT_DB_ALIAS], item)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 214, in __getitem__
0e8ee44abd93_[project_name]_web_1 | backend = load_backend(db['ENGINE'])
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 111, in load_backend
0e8ee44abd93_[project_name]_web_1 | return import_module('%s.base' % backend_name)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
0e8ee44abd93_[project_name]_web_1 | return _bootstrap._gcd_import(name[level:], package, level)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 6, in <module>
0e8ee44abd93_[project_name]_web_1 | from .features import DatabaseFeatures
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/features.py", line 1, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/backends/base/features.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.db import models
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | import django.contrib.gis.db.models.functions # NOQA
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis import forms, gdal
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | from .fields import ( # NOQA
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal import GDALException
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal.datasource import DataSource
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/datasource.py", line 39, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal.driver import Driver
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/libgdal.py", line 50, in <module>
0e8ee44abd93_[project_name]_web_1 | lgdal = CDLL(lib_path)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/ctypes/__init__.py", line 374, in __init__
0e8ee44abd93_[project_name]_web_1 | self._handle = _dlopen(self._name, mode)
0e8ee44abd93_[project_name]_web_1 | OSError: /opt/homebrew/Cellar/gdal/3.3.0_2/lib/libgdal.dylib: cannot open shared object file: No such file or directory
在地址“/opt/homebrew/Cellar/gdal/3.3.0_2/lib/libgdal.dylib”,我只看到文件 libgdal.dylib 的快捷方式。我不知道为什么以及是否需要修复它或者它是正常的。
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'postgis',
'USER': 'postgis',
'PASSWORD': 'postgis',
'HOST': 'db',
'PORT': 5432,
}
}
和
GDAL_LIBRARY_PATH = '/opt/homebrew/Cellar/gdal/3.2.2_3/lib/libgdal.dylib'
我的Docker文件:
FROM python:3
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
RUN apt-get install gdal-bin
COPY . /code/
我的 docker_compose.yaml 文件:
version: "3.9"
services:
db:
image: postgis/postgis
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- ALLOW_IP_RANGE=0.0.0.0/0
ports:
- 5432:5432
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
如果我尝试重现此错误,有时几分钟后它会添加类似 64a949117135_[project_name]_db_1 | CREATE EXTENSION ^[[C
或崩溃消息的内容,并且不会继续。
我从错误消息中建议的列表中严格选择 gdal
版本后问题得到解决。在那之前,我只有最新版本。
问题是:由于 OSError: /opt/homebrew/Cellar/gdal/3.3.0_2/lib/libgdal.dylib: cannot open shared object file: No such file or directory
,Docker 没有正确 运行。
我当前的任务只是将 GeoDjango 添加到我现有的 Django dockerized 项目中,使用 PostGIS 数据库。我用 postgis/postgis.
我猜是因为 gdal 安装不正确导致出错。我用 Homebrew 安装了 gdal。老实说,如果我使用 Docker.
,我不明白为什么我的机器上需要 gdal现在我在 MacBook Air(M1,2020)和所有软件包的最新版本上使用 Big Sur OS。
我找到了很多类似案例的描述,但和我的不完全一样,原因也不一样。
我想弄清楚我遇到的是什么问题,为什么会出现,以及如何解决。
非常感谢任何帮助。
详情:
如果我这样做 docker compose up
,我会看到一个正常的过程开始,然后是一个错误:
(venv) [computer_name]@G-MacBook-Air-2 [project_name] % docker compose up
[+] Running 2/0
⠿ Container 64a949117135_[project_name]_db_1 Created 0.0s
⠿ Container 0e8ee44abd93_[project_name]_web_1 Created 0.0s
Attaching to 0e8ee44abd93_[project_name]_web_1, 64a949117135_[project_name]_db_1
64a949117135_[project_name]_db_1 |
64a949117135_[project_name]_db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
64a949117135_[project_name]_db_1 |
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.354 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.358 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.358 UTC [1] LOG: listening on IPv6 address "::", port 5432
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.365 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.386 UTC [62] LOG: database system shutdown was interrupted; last known up at 2021-06-25 11:05:06 UTC
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.549 UTC [62] LOG: database system was not properly shut down; automatic recovery in progress
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.555 UTC [62] LOG: redo starts at 0/1F45190
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.556 UTC [62] LOG: invalid record length at 0/1F451C8: wanted 24, got 0
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.556 UTC [62] LOG: redo done at 0/1F45190
64a949117135_[project_name]_db_1 | 2021-06-25 11:10:50.614 UTC [1] LOG: database system is ready to accept connections
0e8ee44abd93_[project_name]_web_1 | Exception in thread django-main-thread:
0e8ee44abd93_[project_name]_web_1 | Traceback (most recent call last):
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
0e8ee44abd93_[project_name]_web_1 | self.run()
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/threading.py", line 892, in run
0e8ee44abd93_[project_name]_web_1 | self._target(*self._args, **self._kwargs)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
0e8ee44abd93_[project_name]_web_1 | fn(*args, **kwargs)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
0e8ee44abd93_[project_name]_web_1 | autoreload.raise_last_exception()
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
0e8ee44abd93_[project_name]_web_1 | raise _exception[1]
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute
0e8ee44abd93_[project_name]_web_1 | autoreload.check_errors(django.setup)()
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
0e8ee44abd93_[project_name]_web_1 | fn(*args, **kwargs)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
0e8ee44abd93_[project_name]_web_1 | apps.populate(settings.INSTALLED_APPS)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
0e8ee44abd93_[project_name]_web_1 | app_config.import_models()
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 211, in import_models
0e8ee44abd93_[project_name]_web_1 | self.models_module = import_module(models_module_name)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
0e8ee44abd93_[project_name]_web_1 | return _bootstrap._gcd_import(name[level:], package, level)
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap_external>", line 855, in exec_module
0e8ee44abd93_[project_name]_web_1 | File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/models.py", line 2, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
0e8ee44abd93_[project_name]_web_1 | class AbstractBaseUser(models.Model):
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 122, in __new__
0e8ee44abd93_[project_name]_web_1 | new_class.add_to_class('_meta', Options(meta, app_label))
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class
0e8ee44abd93_[project_name]_web_1 | value.contribute_to_class(cls, name)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/models/options.py", line 206, in contribute_to_class
0e8ee44abd93_[project_name]_web_1 | self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/__init__.py", line 28, in __getattr__
0e8ee44abd93_[project_name]_web_1 | return getattr(connections[DEFAULT_DB_ALIAS], item)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 214, in __getitem__
0e8ee44abd93_[project_name]_web_1 | backend = load_backend(db['ENGINE'])
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 111, in load_backend
0e8ee44abd93_[project_name]_web_1 | return import_module('%s.base' % backend_name)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
0e8ee44abd93_[project_name]_web_1 | return _bootstrap._gcd_import(name[level:], package, level)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 6, in <module>
0e8ee44abd93_[project_name]_web_1 | from .features import DatabaseFeatures
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/features.py", line 1, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/backends/base/features.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.db import models
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | import django.contrib.gis.db.models.functions # NOQA
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis import forms, gdal
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
0e8ee44abd93_[project_name]_web_1 | from .fields import ( # NOQA
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal import GDALException
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal.datasource import DataSource
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/datasource.py", line 39, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal.driver import Driver
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
0e8ee44abd93_[project_name]_web_1 | from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/gis/gdal/libgdal.py", line 50, in <module>
0e8ee44abd93_[project_name]_web_1 | lgdal = CDLL(lib_path)
0e8ee44abd93_[project_name]_web_1 | File "/usr/local/lib/python3.9/ctypes/__init__.py", line 374, in __init__
0e8ee44abd93_[project_name]_web_1 | self._handle = _dlopen(self._name, mode)
0e8ee44abd93_[project_name]_web_1 | OSError: /opt/homebrew/Cellar/gdal/3.3.0_2/lib/libgdal.dylib: cannot open shared object file: No such file or directory
在地址“/opt/homebrew/Cellar/gdal/3.3.0_2/lib/libgdal.dylib”,我只看到文件 libgdal.dylib 的快捷方式。我不知道为什么以及是否需要修复它或者它是正常的。
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'postgis',
'USER': 'postgis',
'PASSWORD': 'postgis',
'HOST': 'db',
'PORT': 5432,
}
}
和
GDAL_LIBRARY_PATH = '/opt/homebrew/Cellar/gdal/3.2.2_3/lib/libgdal.dylib'
我的Docker文件:
FROM python:3
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
RUN apt-get install gdal-bin
COPY . /code/
我的 docker_compose.yaml 文件:
version: "3.9"
services:
db:
image: postgis/postgis
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- ALLOW_IP_RANGE=0.0.0.0/0
ports:
- 5432:5432
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
如果我尝试重现此错误,有时几分钟后它会添加类似 64a949117135_[project_name]_db_1 | CREATE EXTENSION ^[[C
或崩溃消息的内容,并且不会继续。
我从错误消息中建议的列表中严格选择 gdal
版本后问题得到解决。在那之前,我只有最新版本。