Help with weasyprint installation on docker

Good Evening Everyone

I install weasyprint on my mac with Home Brew. I just try to deploy the new code on Fly and I update the requirements.txt but it looks like it is having a problem installing the weasyprint package. i had problems until i used home brew. Any thoughts. On how I can fix this

I see these errors in the Logs
n _load_backend_lib
2023-12-05T00:50:29Z app[2865332ce72058] dfw [info] raise OSError(msg)
2023-12-05T00:50:29Z app[2865332ce72058] dfw [info]OSError: cannot load library ‘gobject-2.0-0’: gobject-2.0-0: cannot open shared object file: No such file or directory. Additionally, ctypes.util.find_library() did not manage to locate a library called ‘gobject-2.0-0’

caveat: I’m not a python dev

that’s indicating the underlying gtk library isn’t findable by your app. it looks like WeasyPrint has good instructions for installing the dependencies. you’d need to make sure those are getting installed in your Dockerfile.

if you have tests, it would be great to run those through your docker image. testing that way it’s a nice way to rule out platform specific stuff from application logic bugs or deployment artifact bugs

I got it to work on my local system. But when fly update docker it fail. I not a docker person.


I try to update the docker file and I have no experience with Docker

Here the file
ARG PYTHON_VERSION=3.11-slim-bullseye



install psycopg2 dependencies.

RUN apt-get update && apt-get install -y
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /code


COPY requirements.txt /tmp/requirements.txt
RUN set -ex &&
pip install --upgrade pip &&
pip install -r /tmp/requirements.txt &&
rm -rf /root/.cache/
COPY . /code

ENV SECRET_KEY “i3UJ0S7ya2xC02RbqbmZ4p3lPeCkoW6BxxUWEwqM6GLFA350qz”
RUN python collectstatic --no-input

RUN apk add --update --no-cache curl jq py3-configobj py3-pip py3-setuptools python3 python3-dev

RUN apk add cairo-dev pango-dev gdk-pixbuf-dev py-lxml shared-mime-info openjpeg-dev freetype-dev
libpng-dev gettext libxml2-dev libxslt-dev

RUN apk add make automake libffi-dev gcc linux-headers g++ py3-brotli musl-dev postgresql-dev zlib-dev jpeg-dev

RUN pip3 install -r requirements.txt


CMD [“gunicorn”, “–bind”, “:8000”, “–workers”, “2”, “django_project.wsgi”]

I get this error with I try to deploy

Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c apk add --update --no-cache curl jq py3-configobj py3-pip py3-setuptools python3 python3-dev]: exit code: 127

Any Ideas

Thanks you

I fix the problem using this link