Search code examples
pythonmacospipmacportsweasyprint

Trouble running WeasyPrint after installing El Capitan (OSX 10.11)


I recently updated my OS on my mac to El Capitan and since then have been running into issues trying to run WeasyPrint. I have updated macports, uninstalled and reinstalled all of the macport dependencies. I've also uninstalled and reinstalled WeasyPrint via pip with no issues, but still it doesn't run. I also have the export DYLD_FALLBACK_LIBRARY_PATH="/opt/local/lib" in my ~/.profile which helped solve the import errors and allowed WeasyPrint to run before I had El Capitan installed. When i type weasyprint --help into the terminal i get the following output/error:

File "main.py", line 14, in <module>
    import nextline_webapp.quotes                   # pylint: disable=unused-import
  File "/Users/joshsacks/NextLine/nextline_webapp/quotes.py", line 8, in <module>
    from flask_weasyprint import HTML, render_pdf
  File "/Library/Python/2.7/site-packages/flask_weasyprint/__init__.py", line 13, in <module>
    import weasyprint
  File "/Library/Python/2.7/site-packages/weasyprint/__init__.py", line 336, in <module>
    from .css import PARSER, preprocess_stylesheet
  File "/Library/Python/2.7/site-packages/weasyprint/css/__init__.py", line 30, in <module>
    from . import computed_values
  File "/Library/Python/2.7/site-packages/weasyprint/css/computed_values.py", line 18, in <module>
    from .. import text
  File "/Library/Python/2.7/site-packages/weasyprint/text.py", line 18, in <module>
    import cairocffi as cairo
  File "/Library/Python/2.7/site-packages/cairocffi/__init__.py", line 46, in <module>
    cairo = dlopen(ffi, 'cairo', 'cairo-2')
  File "/Library/Python/2.7/site-packages/cairocffi/__init__.py", line 43, in dlopen
    raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2

It looks like a path problem, but I've tried everything i can think of. Any suggestions?


Solution

  • Ok so I found a solution (without changing any of the original weasyprint or cairocffi files). Apparently OS X 10.11 introduces SIP which disables the use of DYLD path variables. To get around this I disabled SIP. The instructions to do so are here. Basically hold command + r when booting up. Click utilities at the top and go into the terminal. type in csrutil disable then reboot and that should fix it.