5

Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']

using the python:3.5.1 image I am trying to run a container that includes among other things it installs in requirements.txt shapely. When the docker container tries to install shapely I get the above error.

RUN apt-get install libgeos-dev

was something I saw trying to search the issue but that returns unable to locate package libgeos-dev

summary:

expected conditions: including shapely in the requirements.txt file results ins shapely being installed when the docker container is built actual conditions: An error message is recieved during build Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']

Steps to reproduce:

use docker-compose to build on

Docker-compose.yml:

app:
        build: ${APP_REPO}

Dockerfile:

FROM python:3.5.1-onbuild

Requirements.txt:

shapely

(Simplified to attempt to isolate issues.)

lathomas64
  • 1,612
  • 5
  • 21
  • 47

3 Answers3

7

For alpine, just run following Docker command:

RUN apk add --no-cache \
gcc \
libc-dev \
geos-dev \
&& pip install shapely

This will install shapely with all the proper dependencies for geo and C related dependencies for the shapely for alpine

Tushar Seth
  • 563
  • 7
  • 15
3

I found a solution from: https://github.com/calendar42/docker-python-geos/blob/master/Dockerfile

ENV PYTHONUNBUFFERED 1

#### Install GEOS ####
# Inspired by: https://hub.docker.com/r/cactusbone/postgres-postgis-sfcgal/~/dockerfile/

ENV GEOS http://download.osgeo.org/geos/geos-3.5.0.tar.bz2

#TODO make PROCESSOR_COUNT dynamic
#built by docker.io, so reducing to 1. increase to match build server processor count as needed
ENV PROCESSOR_COUNT 1

WORKDIR /install-postgis

WORKDIR /install-postgis/geos
ADD $GEOS /install-postgis/geos.tar.bz2
RUN tar xf /install-postgis/geos.tar.bz2 -C /install-postgis/geos --strip-components=1
RUN ./configure && make -j $PROCESSOR_COUNT && make install
RUN ldconfig
WORKDIR /install-postgis

I copied this into my dockerfile before the line

pip install requirements.txt

and the shapely install worked.

It stalls out doing the build occasionally but the main problem was solved.

lathomas64
  • 1,612
  • 5
  • 21
  • 47
  • This looks correct, but I think you could also build a wheel for the package and install that. – dnephin Sep 09 '16 at 13:55
  • Stuff i found about wheel files when I initially looked into the problem suggested they were a windows specific thing, is this not true? – lathomas64 Sep 12 '16 at 19:28
  • It is not true at all. They are more common on windows because it's often harder for windows users to compile things (they don't always have the same easy access to a compiler), and pypi only includes windows wheels I believe. You can build and use wheels on linux and osx, but you have to build them for your platform. – dnephin Sep 13 '16 at 18:09
1

I had the same problem for my python application. What worked for me was the following:

FROM python:3.8-slim-buster


WORKDIR /app

COPY requirements.txt requirements.txt

RUN apt-get update && apt-get install -y \
    libgeos-dev

RUN pip install -r requirements.txt

COPY . /app/

CMD ["python3", "app.py"]
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 13 '21 at 21:21