pythondjangodockerpostgis

AttributeError: /usr/lib/libgdal.so.20: undefined symbol: OSRSetAxisMappingStrategy


I'm trying to start my project in docker, it was working great, but now something happened and it can't start. It crashes with

AttributeError: /usr/lib/libgdal.so.20: undefined symbol: OSRSetAxisMappingStrategy

I searched a lot but have no idea how to make it work. I've tried updating all the libs I have, but no effect whatsoever. Here's what I use:

My docker configuration:

FROM python:3.11-buster

# Set work directory
WORKDIR /app

# Install system dependencies
RUN apt-get update \
    && apt-get install -y \
        binutils \
        libproj-dev \
        gdal-bin \
        libgdal-dev \
        postgresql-client \
    && rm -rf /var/lib/apt/lists/* \

ENV CPLUS_INCLUDE_PATH=/usr/include/gdal
ENV C_INCLUDE_PATH=/usr/include/gdal

# Install Poetry
COPY pyproject.toml poetry.lock* ./
RUN pip install poetry && \
    poetry config virtualenvs.create false && \
    poetry install --no-dev

# Copy the application code
COPY . .

# Expose ports
EXPOSE 8000
EXPOSE 8001

# Run the application
ENTRYPOINT ["sh", "-c", "poetry run gunicorn app.wsgi:application --bind 0.0.0.0:8000"]

Solution

  • not sure if this is the answer you're looking for, but I have experienced the same problem today and resolved it by upgrading from python:3.11-buster to python:3.12-bookworm.

    This is my updated docker config:

    FROM python:3.12-bookworm
    
    # Create and set the directory where the source code is stored.
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    
    # Set environment variables. Note language set to en-GB.
    ENV PYTHONUNBUFFERED 1
    ENV PYTHONDONTWRITEBYTECODE 1
    ENV LANG en_GB.UTF-8
    ENV PYTHONIOENCODING utf_8
    
    # Install system packages required by Wagtail, Django and Psycopg2 and PostGIS
    RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \
        build-essential \
        libpq-dev \
        gdal-bin \
        libgdal-dev \
        libmariadb-dev-compat libmariadb-dev \
        libjpeg62-turbo-dev \
        zlib1g-dev \
        libwebp-dev \
        python-dev-is-python3 \
        && rm -rf /var/lib/apt/lists/*
    
    # Copy the source code and install dependencies
    COPY Pipfile Pipfile.lock /usr/src/app/
    RUN pip install --upgrade pip
    RUN pip install pipenv && pipenv install --system
    

    Note, I also had to swap libmariadbclient-dev to libmariadb-dev-compat libmariadb-dev and python-dev to python-dev-is-python3

    Hope this helps.