Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeasyPrint install instructions for Alpine Linux #699

Closed
elyak123 opened this issue Sep 25, 2018 · 10 comments
Closed

WeasyPrint install instructions for Alpine Linux #699

elyak123 opened this issue Sep 25, 2018 · 10 comments
Labels
documentation Problems or improvements needed on the documentation or on the website

Comments

@elyak123
Copy link

Just wanted to recommend adding to documentation instructions to install WeasyPrint in Alpine Linux 3.6. It took me a while but I made it work with this command:
apk --update --upgrade add gcc musl-dev jpeg-dev zlib-dev libffi-dev cairo-dev pango-dev gdk-pixbuf

If someone else have a more efficient aproach (important when working with docker containers for small size images) can comment on this.

@liZe liZe added the documentation Problems or improvements needed on the documentation or on the website label Oct 11, 2018
@liZe liZe closed this as completed in c5babb2 Oct 11, 2018
@liZe
Copy link
Member

liZe commented Oct 11, 2018

Thank you!

@VDShark
Copy link

VDShark commented Jan 17, 2019

Also spent some time for finding non redundant solution.

As a result of experiments, found next
1) these packages required for running cairo pango gdk-pixbuf
2) these packages required only on the building stage gcc musl-dev libffi-dev jpeg-dev zlib-dev (and could be deleted after that for keeping image as small/clean as possible )

Alpine broke ldconfig...
docker-library/python#111

So unfortunately it looks most simple way now - include gcc and dev versions into build.
This is awful, because size of the image increased 2 times...

packages for run: gcc cairo-dev pango-dev gdk-pixbuf
packages for build: musl-dev jpeg-dev zlib-dev libffi-dev

P.S. Will hope they will fix this, workarounds with LD_LIBRARY_PATH also not looks as working now (waiting PR into python)

@VDShark
Copy link

VDShark commented Apr 15, 2019

Finally!
With the latest versions of alpine & weasyprint we can keep build pretty small & clean.

Here my current approach:

FROM python:3.7-alpine
ENV PYTHONUNBUFFERED 1

RUN apk --update --upgrade --no-cache add \
    cairo-dev pango-dev gdk-pixbuf

...

ADD /etc/pip/requirements.txt /code/requirements.txt
RUN set -ex \
    && apk add --no-cache --virtual .build-deps \
        musl-dev gcc jpeg-dev zlib-dev libffi-dev \
    && pip install --no-cache-dir -r /code/requirements.txt \
    && apk del .build-deps

...

Packages cairo-dev pango-dev gdk-pixbuf need in runtime, so we kept them.
Other ones need only on building stage - so we clean.

In requirements.txt just weasyprint and my specific dependencies, not related to this issue.

@dploeger
Copy link

dploeger commented Jun 2, 2021

For somebody who came around this issue because they couldn't install weasyprint on Alpine now, here's the two lines to get it installed:

apk add python3 py3-pip pango gcc musl-dev py3-wheel python3-dev libffi-dev zlib-dev jpeg-dev
pip install weasyprint

@dploeger
Copy link

dploeger commented Jun 2, 2021

And this is also documented which I somehow overread 🙄

SchrodingersGat added a commit to SchrodingersGat/InvenTree that referenced this issue Jul 10, 2023
SchrodingersGat added a commit to inventree/InvenTree that referenced this issue Jul 10, 2023
* Docker: add missing reporting libs

* Fix pango / cairo libs

Ref: Kozea/WeasyPrint#699

* Move to where it will actually do something

* Remove continuation

* Remove dev packages
@jo-bitsch
Copy link
Contributor

I recently used the following commands for my docker containers (alpine 3.17):

apk add python3 py3-pip pango
pip install weasyprint
weasyprint -h

which of course uses the precompiled python wheels for musllinux for cffi, Pillow, fonttools, brotli, zopfli, but worked excellent for me to produce a small image, without having to install and uninstall build dependencies.

I tested this on CPython 3.10 musllinux: musl 1.1+ x86-64, but I'm confident, it would also work for aarch64.

@liZe
Copy link
Member

liZe commented Nov 5, 2024

I recently used the following commands for my docker containers (alpine 3.17):

It can probably work without the -dev packages if wheels are available for all Python dependencies. But you’ll need for sure Pango, and harfbuzz-subset if you want fast font subsetting.

If someone wants to update the list, please test with a minimal Alpine installation and open a pull request!

@jo-bitsch
Copy link
Contributor

To test that all the libraries load in a minimal alpine install, you can run:

docker run -ti alpine sh -c "apk add py3-pip pango && pip install weasyprint && weasyprint -h"

To properly use it, I have some fonts locally available, alternatively you can add font-dejavu as an additional dependency.

pango depends on harfbuzz which already provides libharfbuzz-subset.so.0, so I'm not sure if I should add it as an explicit dependency.

I'll open a pull-request on the documentation later this week.

Thanks, for the excellent work on weasyprint.

@liZe
Copy link
Member

liZe commented Nov 6, 2024

To properly use it, I have some fonts locally available, alternatively you can add font-dejavu as an additional dependency.

We usually don’t include fonts in required packages, and let users install the ones they want or use @font-face fonts.

pango depends on harfbuzz which already provides libharfbuzz-subset.so.0, so I'm not sure if I should add it as an explicit dependency.

I’m not an Alpine user, so I don’t know how its package manager works. It looks like libharfbuzz-subset.so.0 is provided by the harfbuzz-subset package, that’s a sub package of harfbuzz. Are all subpackages automatically installed when a package is installed?

I'll open a pull-request on the documentation later this week.

Thanks, for the excellent work on weasyprint.

Thanks a lot!

@jo-bitsch
Copy link
Contributor

I just remembered, there is a better way in alpine to be explicit about the dependencies, directly referring to the .so files like this:

apk add so:libgobject-2.0.so.0 so:libpango-1.0.so.0 so:libharfbuzz.so.0 so:libharfbuzz-subset.so.0 so:libfontconfig.so.1 so:libpangoft2-1.0.so.0

This form is slightly more verbose but stable against package splits and very explicitly the actual dependency that is referred to in ffi.py

I collected the list from

gobject = _dlopen(
ffi, 'libgobject-2.0-0', 'gobject-2.0-0', 'gobject-2.0',
'libgobject-2.0.so.0', 'libgobject-2.0.dylib', 'libgobject-2.0-0.dll')
pango = _dlopen(
ffi, 'libpango-1.0-0', 'pango-1.0-0', 'pango-1.0', 'libpango-1.0.so.0',
'libpango-1.0.dylib', 'libpango-1.0-0.dll')
harfbuzz = _dlopen(
ffi, 'libharfbuzz-0', 'harfbuzz', 'harfbuzz-0.0',
'libharfbuzz.so.0', 'libharfbuzz.0.dylib', 'libharfbuzz-0.dll')
harfbuzz_subset = _dlopen(
ffi, 'libharfbuzz-subset-0', 'harfbuzz-subset', 'harfbuzz-subset-0.0',
'libharfbuzz-subset.so.0', 'libharfbuzz-subset.0.dylib', 'libharfbuzz-subset-0.dll',
allow_fail=True)
fontconfig = _dlopen(
ffi, 'libfontconfig-1', 'fontconfig-1', 'fontconfig',
'libfontconfig.so.1', 'libfontconfig.1.dylib', 'libfontconfig-1.dll')
pangoft2 = _dlopen(
ffi, 'libpangoft2-1.0-0', 'pangoft2-1.0-0', 'pangoft2-1.0',
'libpangoft2-1.0.so.0', 'libpangoft2-1.0.dylib', 'libpangoft2-1.0-0.dll')

Are all subpackages automatically installed when a package is installed?

No, not in general. However, in this specific case harfbuzz provides the file, also.

jo-bitsch added a commit to jo-bitsch/WeasyPrint that referenced this issue Nov 6, 2024
As per the discussion in Kozea#699, document an easier way to install WeasyPrint from PyPI when using prebuilt wheels.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Problems or improvements needed on the documentation or on the website
Projects
None yet
Development

No branches or pull requests

5 participants