4

I want to run some Python code from the WeasyPrint library on a server running Debian GNU/Linux 8. The code actually appears to be working, except WeasyPrint gives a warning every time the code is run:

/home/username/venv/lib/python3.7/site-packages/weasyprint/document.py:36: UserWarning: There are known rendering problems and missing features with cairo < 1.15.4.
/home/username/venv/lib/python3.7/site-packages/weasyprint/fonts.py:44: UserWarning: @font-face support needs Pango >= 1.38

To investigate this, I first looked at what versions I had in my pip list. When installing WeasyPrint, I used python -m pip install weasyprint, which installed maybe 10 dependencies. However, the only stuff related to Cairo appears to be CairoSVG v2.4.2, cairocffi v1.1.0, and cffi 1.12.3. Nothing in my pip list has just the name "Cairo". I thought that maybe cairocffi was possibly what I needed to look at, but using python -m pip install cairocffi -U yielded no found update. Further, the Cairo website suggests using sudo apt-get install libcairo2-dev, however the prompt returns a message saying that "libcairo2-dev is already the newest version."

I became especially confused when taking the opportunity at this point in my meandering search to investigate the problem with Pango. I used find -type d -name "*pango*" in the Python virtual environment directory I'm using, and found no directory even with the name pango. According to the website, Pango is integrated with Cairo, but since python -m pip install weasyprint installs cairocffi, and my find returned no results, I'm confused as to where the Pango functionality even is currently. I found the source packages for Pango, but I don't know where I would even put these files to replace the existing code. I also have no experience downloading/installing Python packages from source, let alone when I can't even figure out how my current setup is working.

What is the relationship between cairocffi and cairo? Likewise, what is Pango's relationship with cairocffi versus cairo? How should I continue forward to resolve the version warnings I'm encountering?

If this is not the right place to post this, please direct me to a more appropriate area and I'll take it there.

Nelson Frew
  • 107
  • 1
  • 9

2 Answers2

1

CairoGraphics is an integration of Pango with Cairo (http://cairographics.org/) for text handling and graphics rendering. cairocffi is the python version of CairoGraphics. Therefore, that seems to be where the error lies.

Specific to your question, cairocffi is imported as 'cairo' in weasyprint's text.py and Pango is probably one of cairo's dependencies. Therefore, there seems to be something wrong with your cairocffi installation. Could you try using pip3 and see if that makes any difference:

pip3 install cairocffi
Jack
  • 313
  • 5
  • 22
0

Pango and Cairo are C libraries and not Python packages. You usually have to install them through your operating system’s package manager.

You can check the installed Pango version with

pango-view --version

Unfortunately, as these are core libraries for font and UI rendering, it is unlikely that you can upgrade them without upgrading the whole system.

For instance, Pango is only distributed in source form on their download page, which explicitly states:

Building Pango from source can at times be a difficult process.

If there are packages of Pango available from your operating system vendor, you should use those packages. Virtually all distributions of Linux install Pango by default; in fact, if you are using Linux, Pango may well be rendering the text you are reading at the moment.

Trying to install a newer copy of Pango along side your operating system's version is especially challenging. If you want to do this, we would recommend using JHBuild.

(emphasis is my own)

Didier L
  • 18,905
  • 10
  • 61
  • 103