Weasyprint: Cairo warning

Created on 7 Aug 2019  Â·  9Comments  Â·  Source: Kozea/WeasyPrint

There is a warning in document.py like this:

import cairocffi as cairo

...

if cairo.cairo_version() < 11504:
    warnings.warn(
        'There are known rendering problems and missing features with '
        'cairo < 1.15.4. WeasyPrint may work with older versions, but please '
        'read the note about the needed cairo version on the "Install" page '
        'of the documentation before reporting bugs. '
        'http://weasyprint.readthedocs.io/en/latest/install.html')

However, latest version of cairocffi package is 1.0.2 at the moment. This is a rather annoying warning and there is no programmatic way to get rid of it. Could you give more info on this?

Most helpful comment

You can kill this with:

import warnings
warnings.filterwarnings("ignore", module="weasyprint")

Just put it in settings.py if you are using Django.

All 9 comments

The warning isn't about the Python package cairocffi but about the GTK library cairo. Cairocffi just makes cairo library available.
The way to update cairo library and get rid of the warning is OS specific. Maybe a look at the "Install" page of the documentation gives you a hint.

I've figured out that the warning is about the GTK library cairo, but I am now facing the problem of installing the latest, or at least more recent version than 1.15.4 on my Ubuntu 16.04 Docker container. Apparently apt-get install only gets till version 1.14.8-1. Do you have any hint to how to achieve this?

Thanks a lot.

Do you have any hint to how to achieve this?

It won't be easy to safely get a more recent version of Cairo on 16.04 (that's more than 3 years old).

You can either:

  • just ignore the warning if you don't need links, or
  • use an older version of WeasyPrint (0.42.3 will probably be OK), or
  • use a more recent version of Ubuntu.

Hi everyone,

I managed to install the 1.15.4 package but Weasyprint is still detecting the 1.14 version. Any tips on how to make Weasyprint make use of the new cairo package?

@bobozar What*s your OS?

@Tontyna Ubuntu 16.04

@bobozar Sorry, don't know enough about Ubuntu to help you.

Hello @bobozar,

Depending on what you really want to do, the best solution may be really different.

If you just want to remove the warning, you can hide warnings using python -W ignore or setting the PYTHONWARNINGS=ignore environment variable. You can also remove the lines from WeasyPrint (they're at the beginning of document.py).

If you want to use WeasyPrint with its latest features, you really should upgrade your Ubuntu version. You'll get a recent version of Cairo, but also of other libraries (including Pango, Harfbuzz…). Version 18.04 is LTS too.

If you really want to use Ubuntu 16.04 and Cairo 1.15.4+, then you're on your own :cry:. LTS versions of Ubuntu are meant to be stable, and including a more recent version of a package can have unpredictable results (Cairo is used by a lot of libraries). If you replace the current version of Cairo by a more recent one, you may break things. If you manage to install both, then you'll have to play with environment variables to make WeasyPrint import the recent one. Use the version of WeasyPrint (0.42.3) that was made for this version of Cairo, you'll save a lot of time :wink:.

You can kill this with:

import warnings
warnings.filterwarnings("ignore", module="weasyprint")

Just put it in settings.py if you are using Django.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zopyx picture zopyx  Â·  5Comments

grewn0uille picture grewn0uille  Â·  4Comments

ajakubo1 picture ajakubo1  Â·  5Comments

elyak123 picture elyak123  Â·  3Comments

antuaneacion picture antuaneacion  Â·  3Comments