Исключение GEOSException в контейнере dev для geodjango с postgis для python 3.12
Я пытаюсь настроить контейнер dev для разработки приложения geodjango.
Контейнер dev запускается и работает, но при переходе в админке к обзору модели, содержащей PointField, я получаю следующее сообщение об ошибке:
Сообщение об ошибке:
GEOSException at /admin/phyiscal_assets/plant/
Error encountered checking Geometry returned from GEOS C function "GEOSWKBReader_read_r".
Request Method: GET
Request URL: http://localhost:8002/admin/phyiscal_assets/plant/
Django Version: 5.0.7
Exception Type: GEOSException
Exception Value:
Error encountered checking Geometry returned from GEOS C function "GEOSWKBReader_read_r".
Exception Location: /workspaces/django-test/.venv/lib/python3.12/site-packages/django/contrib/gis/geos/prototypes/errcheck.py, line 33, in check_geom
Raised during: django.contrib.admin.options.changelist_view
Python Executable: /workspaces/django-test/.venv/bin/python
Python Version: 3.12.4
Python Path:
['/workspaces/django-test/src/XXX',
'/usr/local/lib/python312.zip',
'/usr/local/lib/python3.12',
'/usr/local/lib/python3.12/lib-dynload',
'/workspaces/django-test/.venv/lib/python3.12/site-packages',
'/workspaces/django-test/src']
Server time: Wed, 31 Jul 2024 15:09:24 +0000
models.py
from django.contrib.gis.db import models #as gis_models
class Plant(models.Model):
"""Model representing a plant."""
name = models.CharField(max_length=200)
city = models.CharField(max_length=200)
country = models.CharField(max_length=200)
location = models.PointField() # lat and long point fields
def __str__(self):
"""String for representing the Model object."""
return self.name
admin.py:
from django.contrib.gis import admin
from .models import Plant
@admin.register(Plant)
class PlantAdmin(admin.ModelAdmin):
list_display = ('name', 'city')
Контейнер DEV (VS Code) создается с помощью:
devcontainer.json:
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"NODE_VERSION": "lts/*",
"POETRY_VERSION": "1.8.3",
"NOX_VERSION": "2024.4.15"
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"lextudio.restructuredtext-pack"
],
"settings": {
"redhat.telemetry.enabled": false,
"github.gitProtocol": "ssh",
"github.copilot.advanced": {},
"workbench.colorTheme": "Default Light Modern",
"notebook.output.scrolling": true,
"notebook.output.wordWrap": true,
"notebook.output.textLineLimit": 200,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.inlineSuggest.enabled": true,
"editor.inlineSuggest.showToolbar": "always",
"editor.formatOnSave": true,
"editor.multiCursorModifier": "ctrlCmd",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"black-formatter.args": [
"--line-length",
"99",
"--skip-magic-trailing-comma"
],
"editor.rulers": [99, 120],
"workbench.colorCustomizations": {
"editorRuler.foreground": "#ff4081"
},
"flake8.args": ["--max-line-length=100"],
"[python]": {
"editor.formatOnType": true,
"editor.insertSpaces": true,
"editor.tabSize": 4,
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.analysis.typeCheckingMode": "off",
"python.testing.pytestEnabled": false,
"[django-html]": {
"djlint.enableLinting": true,
"djlint.profile": "django",
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": true
}
},
"black-formatter.importStrategy": "fromEnvironment",
"git.autofetch": true
}
}
},
"postCreateCommand": "bash ./.devcontainer/post-install.sh",
"runArgs": ["--network=host"], //-p=3000:3000
"remoteUser": "root",
"features": {
"github-cli": "latest"
},
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/django-test,type=bind",
"workspaceFolder": "/workspaces/django-test"
}
Dockerfile:
FROM python:3.12-slim
ARG POETRY_VERSION="none"
ARG NOX_VERSION="none"
ENV DJANGO_ENV=${DJANGO_ENV} \
# python:
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
# pip:
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
# poetry:
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/var/cache/pypoetry'
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache
# extend deb sources
RUN echo "deb http://deb.debian.org/debian/ unstable main contrib non-free" | tee -a /etc/apt/sources.list
RUN apt-get update
RUN apt-get install --no-install-recommends -y software-properties-common
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
bash \
build-essential \
curl \
gettext \
git \
wget \
binutils \
libproj-dev \
python3-dev \
geos-bin \
libpq-dev gdal-bin libgdal-dev
RUN pip3 install setuptools -U
# Poetry
RUN if [ "${POETRY_VERSION}" != "none" ]; then \
pip3 install poetry==${POETRY_VERSION}; \
fi
# Nox
RUN if [ "${NOX_VERSION}" != "none" ]; then \
pip3 install nox-poetry nox==${NOX_VERSION};\
fi
RUN pip3 install psycopg2 -U
post-install.sh:
#!/bin/bash
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
gdal_version = bash -c "ogrinfo --version | cut -d, -f1 | sed 's/.* //'"
poetry add "gdal==$gdal_version"
poetry install
pyproject.toml
[tool.poetry]
name = "XXX"
version = "0.0.8"
description = "XXX"
authors = ["XXX"]
license = "MIT"
readme = "README.md"
homepage = "XXX"
repository = "XXX"
documentation = "XXX"
classifiers = [
"Development Status :: 3 - Alpha",
]
[tool.poetry.urls]
Changelog = "XXX"
[tool.poetry.dependencies]
python = "^3.11"
click = ">=8.0.1"
django = "^5.0.6"
uvicorn = "^0.29.0"
gunicorn = "^22.0.0"
psycopg2 = "^2.9.9"
djangorestframework = "^3.15.1"
django-filter = "^24.2"
markdown = "^3.6"
django-location-field = "^2.7.3"
numpy = "^2.0.1"
gdal = "3.9.1"
djlint = "^1.34.1"
psycopg2-binary = "^2.9.9"
pyproj = "^3.6.1"
pandas = "^2.2.2"
[tool.poetry.group.dev.dependencies]
Pygments = ">=2.10.0"
bandit = ">=1.7.4"
black = ">=21.10b0"
coverage = {extras = ["toml"], version = ">=6.2"}
darglint = ">=1.8.1"
flake8 = ">=4.0.1"
flake8-bugbear = ">=21.9.2"
flake8-docstrings = ">=1.6.0"
flake8-rst-docstrings = ">=0.2.5"
furo = ">=2021.11.12"
isort = ">=5.10.1"
mypy = ">=0.930"
pep8-naming = ">=0.12.1"
pre-commit = ">=2.16.0"
pre-commit-hooks = ">=4.1.0"
pytest = ">=6.2.5"
pyupgrade = ">=2.29.1"
safety = ">=1.10.3"
sphinx = ">=4.3.2"
sphinx-autobuild = ">=2021.3.14"
sphinx-click = ">=3.0.2"
typeguard = ">=2.13.3"
xdoctest = {extras = ["colors"], version = ">=0.15.10"}
myst-parser = {version = ">=0.16.1"}
# djlint = "^1.34.1"
[tool.poetry.scripts]
XXX = "XXX.__main__:main"
[tool.coverage.paths]
source = ["src", "*/site-packages"]
tests = ["tests", "*/tests"]
[tool.coverage.run]
branch = true
source = ["XXX", "tests"]
[tool.coverage.report]
show_missing = true
fail_under = 100
[tool.isort]
profile = "black"
force_single_line = true
lines_after_imports = 2
[tool.mypy]
strict = true
warn_unreachable = true
pretty = true
show_column_numbers = true
show_error_context = true
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Есть идеи, с чего начать? Я пытался обновить пакеты geos и gdal, но безуспешно.