Anentropic
Anentropic

Reputation: 33923

Issues installing Spatialite on Amazon Linux 2 "libgdal.so: undefined symbol: sqlite3_trace_v2"

I am attempting to build Docker image for AWS Lambda running Python with spatialite (for GeoDjango).

After endless problems trying to get GDAL installed I discovered this image https://github.com/lambgeo/docker-lambda (ghcr.io/lambgeo/lambda-gdal:3.8-python3.11) which solved most of that.

However I still need to install Spatialite.

In my Dockerfile I have:

FROM ghcr.io/lambgeo/lambda-gdal:3.8-python3.11 as gdal

RUN yum update -y && \
    yum install -y git autoconf libtool flex bison cmake make \
      tar gzip xz gcc gcc-c++ automake16 libpng-devel nasm \
      readline-devel openssl-devel curl-devel \
      cmake3 && \
    yum clean all && \
    rm -rf /var/cache/yum /var/lib/yum/history

ENV PREFIX /opt

WORKDIR /opt

ENV LD_LIBRARY_PATH $PREFIX/lib:$LD_LIBRARY_PATH

RUN patchelf --force-rpath --set-rpath '$ORIGIN' $PREFIX/lib/libgdal.so

# pkg-config
ENV PKGCONFIG_VERSION=0.29.2
RUN mkdir /tmp/pkg-config \
  && curl -sfL https://pkg-config.freedesktop.org/releases/pkg-config-${PKGCONFIG_VERSION}.tar.gz | tar zxf - -C /tmp/pkg-config --strip-components=1 \
  && cd /tmp/pkg-config \
  && CFLAGS="-O2 -Wl,-S" ./configure --prefix=$PREFIX --with-internal-glib \
  && make -j $(nproc) --silent && make install && make clean \
  && rm -rf /tmp/pkg-config

ENV PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/

# libxml2
RUN mkdir /tmp/libxml2 \
  && curl -sfL https://download.gnome.org/sources/libxml2/2.12/libxml2-2.12.3.tar.xz | tar xJf - -C /tmp/libxml2 --strip-components=1 \
  && cd /tmp/libxml2 \
  && \
    CFLAGS='-O2 -fno-semantic-interposition' \
    PYTHON_CFLAGS='-I/var/lang/include/python3.11' \
    PKG_CONFIG_PATH='/var/lang/lib/pkgconfig/' \
    LDFLAGS='-Wl,-rpath=/var/lang/lib -L/var/lang/lib -lpython3.11' \
    ./configure --prefix=${PREFIX} \
  && make -j $(nproc) --silent && make install && make clean \
  && rm -rf /tmp/libxml2

# spatialite
RUN mkdir /tmp/spatialite \
  && curl -sfL https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-5.1.0.tar.gz | tar zxf - -C /tmp/spatialite --strip-components=1 \
  && cd /tmp/spatialite \
  && CFLAGS='-I/opt/include' LDFLAGS='-L/opt/lib' \
    ./configure --prefix=${PREFIX} \
    --enable-freexl=no --enable-minizip=no --disable-rttopo \
  && make -j $(nproc) --silent && make install && make clean \
  && rm -rf /tmp/spatialite

I have to repeat a few bits from the base image (the exported layer did not include them) like the pkgconfig. Then I have to install libxml2 from src to get round another error.

After some difficulty arriving at the above, Spatialite appears to install successfully.

However when I try to run my Django app I get this error:

  File "/project/.venv/lib/python3.11/site-packages/django/contrib/gis/gdal/libgdal.py", line 71, in <module>
    lgdal = CDLL(lib_path)
            ^^^^^^^^^^^^^^
  File "/var/lang/lib/python3.11/ctypes/__init__.py", line 376, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: /opt/lib/libgdal.so: undefined symbol: sqlite3_trace_v2

In my Django settings.py I have:

GDAL_LIBRARY_PATH = env("GDAL_LIBRARY_PATH", default="")
GEOS_LIBRARY_PATH = env("GEOS_LIBRARY_PATH", default="")
SPATIALITE_LIBRARY_PATH = env("SPATIALITE_LIBRARY_PATH", default="")

and I am setting these values:

ENV GDAL_LIBRARY_PATH=/opt/lib/libgdal.so
ENV GEOS_LIBRARY_PATH=/opt/lib/libgeos.so
ENV SPATIALITE_LIBRARY_PATH=/opt/lib/mod_spatialite.so

I don't find anything very relevant by googling for this error.

There's this Python issue maybe https://bugs.python.org/issue40318 but it appears to have been resolved in Python 3.10 (I'm using 3.11)

Upvotes: 0

Views: 178

Answers (0)

Related Questions