Troubles with Shapely and Alpine
Tags: linux, docker, python, django
Published: 2019-12-19 17:27:26

Hello,
im facing some troubles trying to install shapely on my local environment.

The main reason why so many dependencies are installed via the dockerfile instead on local.txt is in order to find the broken dependency.

DockerFile

FROM python:3.7-alpine

ENV PYTHONUNBUFFERED 1

RUN apk update \
  # psycopg2 dependencies
  && apk add --no-cache --virtual build-deps gcc g++ python3-dev musl-dev \
  && apk add postgresql-dev \
  # Pillow dependencies
  && apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
  # CFFI dependencies
  && apk add libffi-dev py-cffi \
  # Translations dependencies
  && apk add gettext \
  # https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell
  && apk add postgresql-client \
  && apk add --no-cache gcc \
  && apk add --no-cache libc-dev

RUN apk add --no-cache --virtual .build-deps-edge \
        --repository http://dl-cdn.alpinelinux.org/alpine/edge/community \
        --repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
        --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
        gdal-dev geos-dev proj-dev gdal geos proj libcrypto1.1

RUN pip install -U numpy \
&& pip install python-dotenv \
&& pip install selenium \
&& pip install shapely

# Install packages
RUN apk add --no-cache libcurl

# Needed for pycurl
ENV PYCURL_SSL_LIBRARY=openssl

# Install packages only needed for building, install and clean on a single layer
RUN apk add --no-cache --virtual .build-dependencies build-base curl-dev \
    && apk add libxml2-dev libxslt-dev linux-headers gettext-dev \
    && pip install pycurl \
    && apk del .build-dependencies

RUN apk add --update chromium

ENV CHROME_BIN=/usr/bin/chromium-browser
ENV CHROME_PATH=/usr/lib/chromium/

RUN apk add chromium-chromedriver

# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt

COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r//' /entrypoint
RUN chmod +x /entrypoint

COPY ./compose/local/django/start /start
RUN sed -i 's/\r//' /start
RUN chmod +x /start

WORKDIR /app

ENTRYPOINT ["/entrypoint"]


Local.txt

-r ./base.txt


# recommendations are commented

ipdb==0.11  # https://github.com/gotcha/ipdb
# Sphinx==1.8.2  # https://github.com/sphinx-doc/sphinx

# Testing
# ------------------------------------------------------------------------------
mypy==0.650  # https://github.com/python/mypy
pytest==4.0.2  # https://github.com/pytest-dev/pytest
pytest-sugar==0.9.2  # https://github.com/Frozenball/pytest-sugar

# Code quality
# ------------------------------------------------------------------------------
# flake8==3.6.0  # https://github.com/PyCQA/flake8
# coverage==4.5.2  # https://github.com/nedbat/coveragepy


# Django
# ------------------------------------------------------------------------------
# factory-boy==2.11.1  # https://github.com/FactoryBoy/factory_boy

django-debug-toolbar==1.11  # https://github.com/jazzband/django-debug-toolbar
django-extensions==2.1.6
# django-coverage-plugin==1.6.0  # https://github.com/nedbat/django_coverage_plugin
pytest-django==3.4.4  # https://github.com/pytest-dev/pytest-django
pycurl==7.43.0.3
wptools==0.4.17


# For the Soap Client
# ------------------------------------------------------------------------------
lxml==4.4.1
zeep==3.4.0

# For Selenium
# ------------------------------------------------------------------------------
# urllib3==1.25.3
selenium==3.141.0


Base.txt
shapely==1.6.4.post2
Cython==0.29.14
aniso8601==3.0.2
argon2-cffi==19.1.0  # https://github.com/hynek/argon2_cffi
googlemaps==3.0.2
graphene==2.1.5
graphene-django==2.3.0
graphql-core==2.1
graphql-relay==0.4.5
numpy==1.16.3
pandas==0.24.2
promise==2.2.1
psycopg2-binary==2.8.2
pytz==2019.1
requests==2.21.0
Rx==1.6.1
singledispatch==3.4.0.3
six==1.12.0
sqlparse==0.3.0
sentry-sdk==0.7.14 # it should be only in production
beautifulsoup4==4.7.1

# Django
# ------------------------------------------------------------------------------
Django==2.2
django-constance==2.4.0
django-environ==0.4.5
django-graphql-geojson==0.1.4
django-picklefield==2.0
django-graphql-jwt==0.2.2

Output

Collecting shapely Downloading https://files.pythonhosted.org/packages/a2/fb/7a7af9ef7a35d16fa23b127abee272cfc483ca89029b73e92e93cdf36e6b/Shapely-1.6.4.post2.tar.gz (225kB) OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']

Does anyone know why is this happening?

Btw, i've tried install shapely[vectorized] without success

Reference: https://stackoverflow.com/questions/59410626/linux-alpine-oserror-could-not-find-library-geos-c-or-load-any-of-its-variants