Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

django - dlopen() failed to load a library: cairo / cairo-2

This is my view:

from django.conf import settings
from django.http import HttpResponse
from django.template.loader import render_to_string
import weasyprint


    @staff_member_required
    def admin_order_pdf(request, order_id):
        order = get_object_or_404(Order, id=order_id)
        html = render_to_string('orders/order/pdf.html', {'order': order})
        response = HttpResponse(content_type='application/pdf')
        response['Content-Disposition'] = 'filename="order_{}.pdf"'.format(order.id)
        weasyprint.HTML(string=html).write_pdf(response,
                                               stylesheets=[weasyprint.CSS(settings.STATIC_ROOT + 'css/pdf.css')])
        return response

when i want to import (import weasyprint) it gives me a error.

ERROR:

Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/orders/order/
Django Version: 1.8.6
Exception Type: OSError
Exception Value:    
dlopen() failed to load a library: cairo / cairo-2

I already installed weasyprint and cairocffi. I'm using osx El Capitan.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This was solved for me by installing the following dependencies on Ubuntu:

 sudo apt-get install libpango1.0-0
 sudo apt-get install libcairo2
 sudo apt-get install libpq-dev

Check out the dependencies at the link:

http://weasyprint.readthedocs.io/en/latest/install.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...