WEASYPRINT M1 MAC MINI

Viewed 1002

I am running weasyprint but system cannot find the package:

(env) andrestemmett@Andres-Mac-mini MicrocareERP % weasyprint --info
Traceback (most recent call last):
  File "/Users/andrestemmett/Desktop/MicrocareERP/env/bin/weasyprint", line 5, in 
    from weasyprint.__main__ import main
  File "/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/__init__.py", line 322, in 
    from .css import preprocess_stylesheet  # noqa isort:skip
  File "/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/css/__init__.py", line 27, in 
    from . import computed_values, counters, media_queries
  File "/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/css/computed_values.py", line 16, in 
    from ..text.ffi import ffi, pango, units_to_double
  File "/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/text/ffi.py", line 380, in 
    gobject = _dlopen(
  File "/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/text/ffi.py", line 377, in _dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: cannot load library 'gobject-2.0-0': dlopen(gobject-2.0-0, 2): image not found.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'

I have tried to change my symlinks to link to hombrew because i read that weasy print relies on dependencies pango libffi. However when I try that:

sudo ln -s /opt/homebrew/opt/glib/lib/libgobject-2.0.0.dylib /usr/local/lib/gobject-2.0
sudo ln -s /opt/homebrew/opt/pango/lib/libpango-1.0.dylib /usr/local/lib/pango-1.0
sudo ln -s /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.dylib /usr/local/lib/harfbuzz
sudo ln -s /opt/homebrew/opt/fontconfig/lib/libfontconfig.1.dylib /usr/local/lib/fontconfig-1
sudo ln -s /opt/homebrew/opt/pango/lib/libpangoft2-1.0.dylib /usr/local/lib/pangoft2-1.0

Then i get this error:

ln: /usr/local/lib/gobject-2.0: No such file or directory
ln: /usr/local/lib/pango-1.0: No such file or directory
ln: /usr/local/lib/harfbuzz: No such file or directory
ln: /usr/local/lib/fontconfig-1: No such file or directory
ln: /usr/local/lib/pangoft2-1.0: No such file or directory

which I dont understand because i read that this is where my system will look for packages but this location doesnt exist.

Please help!! I am desperate lol

2 Answers

The symlink likely does not work since the directory /usr/local/lib/ does not exist.

To fix this, run

mkdir /usr/local/lib/

So I ended up using xhtml2pdf, which is super easy and fast to implement.

pip install xhtml2pdf

from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
def downloadPDF(request,pk):
        
        queryOrderPlan = OrderPlan.objects.get(id=pk)
        queryItems = queryOrderPlan.orderitem_set.all()

        template_path = 'orderApp/pdfs/itempdf.html'
        context = {"queryItems":queryItems,}

        response = HttpResponse(content_type='application/pdf')
        response['content-Disposition'] = 'attachment; filename="items.pdf"'
        
        template = get_template(template_path)
        html = template.render(context)

        pisa_status = pisa.CreatePDF(html, dest=response)

        if pisa_status.err:
            return HttpResponse("We had some error <pre>" + html + "</pre>")
        
        return response
Related