#1690·Zappa

How to include Pango/Cairo to use Weasyprint with my Django app?

Author: BrachamulCreated Nov 2, 2018Updated Jun 29, 2023

Context

I have deployed a simple Django app which uses Weasyprint.

Expected Behavior

The app should produce PDF files, upon request.

Actual Behavior

The app prints the following exception: cannot load library 'pango-1.0': pango-1.0: cannot open shared object file: No such file or directory. Additionally, ctypes.util.find_library() did not manage to locate a library called 'pango-1.0'

Weasyprint requires Pango and Cairo, which normally need to be installed on the host machine.

Possible Fix

@Prasengupta has published a github repo, weasyprint_for_awslambda to help with importing Pango and Cairo. Unfortunately, I dont fully understand what needs to be done. He says I should Step 1: Download the zip file from this repository. Step 2: Include your main handler file in the folder and zip it, upload the zip folder to aws lambda., but I don't know how to do step 2 with Zappa.

Steps to Reproduce

  1. Create a Django app which uses Weasyprint to produce a PDF, for example : weasyprint.HTML("https://www.google.com/").write_pdf()
  2. Push to AWS
  3. Witness the error message

Your Environment