WeasyPrint fails with error on OSX 10.7.5/homebrew

Created on 26 Apr 2013  Â·  18Comments  Â·  Source: Kozea/WeasyPrint

I've got the following versions of the requirements installed:

$ brew install python cairo pango gdk-pixbuf libxml2 libxslt libffi
Warning: python-2.7.4 already installed
Warning: cairo-1.12.14 already installed
Warning: pango-1.34.0 already installed
Warning: gdk-pixbuf-2.28.1 already installed
Warning: libxml2-2.9.0 already installed
Warning: libxslt-1.1.28 already installed
Warning: libffi-3.0.13 already installed

And when I install using mktmpenv --system-site-packages -i WeasyPrint, I get this output.

When I run WeasyPrint, I get the following:

Traceback (most recent call last):
  File "/Users/brian.hicks/.virtualenvs/ad1794530a0bf80f/bin/weasyprint", line 9, in <module>
    load_entry_point('WeasyPrint==0.19', 'console_scripts', 'weasyprint')()
  File "/Users/brian.hicks/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/pkg_resources.py", line 343, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Users/brian.hicks/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/pkg_resources.py", line 2309, in load_entry_point
    return ep.load()
  File "/Users/brian.hicks/.venvburrito/lib/python/distribute-0.6.35-py2.7.egg/pkg_resources.py", line 2015, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/Users/brian.hicks/.virtualenvs/ad1794530a0bf80f/lib/python2.7/site-packages/weasyprint/__init__.py", line 304, in <module>
    from .css import PARSER, preprocess_stylesheet
  File "/Users/brian.hicks/.virtualenvs/ad1794530a0bf80f/lib/python2.7/site-packages/weasyprint/css/__init__.py", line 30, in <module>
    from . import computed_values
  File "/Users/brian.hicks/.virtualenvs/ad1794530a0bf80f/lib/python2.7/site-packages/weasyprint/css/computed_values.py", line 18, in <module>
    from .. import text
  File "/Users/brian.hicks/.virtualenvs/ad1794530a0bf80f/lib/python2.7/site-packages/weasyprint/text.py", line 18, in <module>
    import cairocffi as cairo
  File "/Users/brian.hicks/.virtualenvs/ad1794530a0bf80f/lib/python2.7/site-packages/cairocffi/__init__.py", line 36, in <module>
    cairo = dlopen(ffi, 'libcairo.so.2', 'libcairo-2.dll', 'cairo', 'libcairo-2')
  File "/Users/brian.hicks/.virtualenvs/ad1794530a0bf80f/lib/python2.7/site-packages/cairocffi/__init__.py", line 31, in dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "/Users/brian.hicks/.virtualenvs/ad1794530a0bf80f/lib/python2.7/site-packages/cffi/api.py", line 111, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/Users/brian.hicks/.virtualenvs/ad1794530a0bf80f/lib/python2.7/site-packages/cffi/api.py", line 364, in _make_ffi_library
    raise OSError("library not found: %r" % (name,))
OSError: library not found: 'libcairo.so.2'

Most helpful comment

Hi, I have just got the same issue on Mac 10.8.4.
Investigated an issue and localization gave me, that:

$ brew install cairo

- returned HTTP 404 error for glib dependency
So, I just made:

$ brew update

After that both installation of cairo and running weasyprint were fine:

$ brew install cairo pango gdk-pixbuf libxml2 libxslt libffi
$ pip install WeasyPrint
$ weasyprint --help

- worked for me

All 18 comments

It looks like the install was successful, it’s only at runtime that dlopen() can not load dynamic libraries. Do you know what’s the full path of any .so or .dylib file installed by the cairo homebrew package? What are the values of the LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, and DYLD_FALLBACK_LIBRARY_PATH environment variables?

Also, are you using the Python installed by Homebrew?

While I was getting the answers to those, I noticed the libcairo formula became keg-only, so it wasn't loaded into /usr/local/lib. Running brew link --force cairo fixed it for me.

I … am not sure what that means. Do you have suggestions for Homebrew instructions I could put in the documentation?

That means they figured it's on OSX by default so they shouldn't link it implicitly. There generally aren't too severe consequences for linking, but it's definitely something that varies on a case-by-case basis. Maybe just mention that it might be the case that it needs to be manually linked? That way people won't keep opening dumb bugs like this one. ;)

Ideally I’d like a set of instructions in the docs that people can follow even if they don’t care about pythons and virtualenvs and shared libraries. I’m trying to figure out what that is on OS X, but I don’t have a Mac to test on :/

A good goal to have! Unfortunately I'm not much help. I don't know enough about cairo and the programs which use it to be of any real assistance. Sorry. I'm willing to help test instructions though, should you need a hand.

Hi, @BrianHicks, I'm having the same problem but I am not using homebrew.

I'm using macports and installed like this:

daniel-mac:lib daniel$ sudo port install py26-lxml cairo pango gdk-pixbuf2 libffi
--->  Computing dependencies for py26-lxml
--->  Cleaning py26-lxml
--->  Computing dependencies for cairo
--->  Cleaning cairo
--->  Computing dependencies for pango
--->  Cleaning pango
--->  Computing dependencies for gdk-pixbuf2
--->  Cleaning gdk-pixbuf2
--->  Cleaning libffi
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.

daniel-mac:lib daniel$ sudo pip install WeasyPrint
Requirement already satisfied (use --upgrade to upgrade): WeasyPrint in /Library/Python/2.6/site-packages
Requirement already satisfied (use --upgrade to upgrade): lxml in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): tinycss==0.3 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.6 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): CairoSVG>=0.4.1 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): cffi>=0.6 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): cairocffi>=0.4 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): Pyphen in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): argparse in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): pycparser in /Library/Python/2.6/site-packages (from cffi>=0.6->WeasyPrint)
Cleaning up...

But I get the same error running WeasyPrint:

Traceback (most recent call last):
  File "/usr/local/bin/weasyprint", line 9, in <module>
    load_entry_point('WeasyPrint==0.19.1', 'console_scripts', 'weasyprint')()
  File "build/bdist.macosx-10.6-universal/egg/pkg_resources.py", line 337, in load_entry_point
  File "build/bdist.macosx-10.6-universal/egg/pkg_resources.py", line 2311, in load_entry_point
  File "build/bdist.macosx-10.6-universal/egg/pkg_resources.py", line 2017, in load
  File "/Library/Python/2.6/site-packages/weasyprint/__init__.py", line 304, in <module>
    from .css import PARSER, preprocess_stylesheet
  File "/Library/Python/2.6/site-packages/weasyprint/css/__init__.py", line 30, in <module>
    from . import computed_values
  File "/Library/Python/2.6/site-packages/weasyprint/css/computed_values.py", line 18, in <module>
    from .. import text
  File "/Library/Python/2.6/site-packages/weasyprint/text.py", line 18, in <module>
    import cairocffi as cairo
  File "/Library/Python/2.6/site-packages/cairocffi/__init__.py", line 36, in <module>
    cairo = dlopen(ffi, 'libcairo.so.2', 'libcairo-2.dll', 'cairo', 'libcairo-2')
  File "/Library/Python/2.6/site-packages/cairocffi/__init__.py", line 31, in dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "/Library/Python/2.6/site-packages/cffi/api.py", line 111, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/Library/Python/2.6/site-packages/cffi/api.py", line 364, in _make_ffi_library
    raise OSError("library not found: %r" % (name,))
OSError: library not found: 'libcairo.so.2'

Do you have an idea what should I do?

I haven't used port in a long time. Find out where they put libs and add it
to your path maybe? It's probably /usr/local/lib?
On Apr 30, 2013 6:36 PM, "pelegrini" [email protected] wrote:

Hi, @BrianHicks https://github.com/BrianHicks, I'm having the same
problem but I am not using homebrew.

I'm using macports and installed like this:

daniel-mac:lib daniel$ sudo port install py26-lxml cairo pango gdk-pixbuf2 libffi
---> Computing dependencies for py26-lxml
---> Cleaning py26-lxml
---> Computing dependencies for cairo
---> Cleaning cairo
---> Computing dependencies for pango
---> Cleaning pango
---> Computing dependencies for gdk-pixbuf2
---> Cleaning gdk-pixbuf2
---> Cleaning libffi
---> Scanning binaries for linking errors: 100.0%
---> No broken files found.

daniel-mac:lib daniel$ sudo pip install WeasyPrint
Requirement already satisfied (use --upgrade to upgrade): WeasyPrint in /Library/Python/2.6/site-packages
Requirement already satisfied (use --upgrade to upgrade): lxml in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): tinycss==0.3 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.6 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): CairoSVG>=0.4.1 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): cffi>=0.6 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): cairocffi>=0.4 in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): Pyphen in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): argparse in /Library/Python/2.6/site-packages (from WeasyPrint)
Requirement already satisfied (use --upgrade to upgrade): pycparser in /Library/Python/2.6/site-packages (from cffi>=0.6->WeasyPrint)
Cleaning up...

But I get the same error running WeasyPrint:

Traceback (most recent call last):
File "/usr/local/bin/weasyprint", line 9, in
load_entry_point('WeasyPrint==0.19.1', 'console_scripts', 'weasyprint')()
File "build/bdist.macosx-10.6-universal/egg/pkg_resources.py", line 337, in load_entry_point
File "build/bdist.macosx-10.6-universal/egg/pkg_resources.py", line 2311, in load_entry_point
File "build/bdist.macosx-10.6-universal/egg/pkg_resources.py", line 2017, in load
File "/Library/Python/2.6/site-packages/weasyprint/init.py", line 304, in
from .css import PARSER, preprocess_stylesheet
File "/Library/Python/2.6/site-packages/weasyprint/css/init.py", line 30, in
from . import computed_values
File "/Library/Python/2.6/site-packages/weasyprint/css/computed_values.py", line 18, in
from .. import text
File "/Library/Python/2.6/site-packages/weasyprint/text.py", line 18, in
import cairocffi as cairo
File "/Library/Python/2.6/site-packages/cairocffi/init.py", line 36, in
cairo = dlopen(ffi, 'libcairo.so.2', 'libcairo-2.dll', 'cairo', 'libcairo-2')
File "/Library/Python/2.6/site-packages/cairocffi/init.py", line 31, in dlopen
return ffi.dlopen(names[0]) # pragma: no cover
File "/Library/Python/2.6/site-packages/cffi/api.py", line 111, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "/Library/Python/2.6/site-packages/cffi/api.py", line 364, in _make_ffi_library
raise OSError("library not found: %r" % (name,))
OSError: library not found: 'libcairo.so.2'

Do you have an idea what should I do?

—
Reply to this email directly or view it on GitHubhttps://github.com/Kozea/WeasyPrint/issues/79#issuecomment-17261018
.

Hi @pelegrini . I can’t seem to find the github issue again, but another Macports user had the same problem and resolved it by making sure to use the Python installed by Macports. Apparently it’s common on OS X to have Python install from multiple sources.

@BrianHicks, the location was /opt/local, but the $PATH was right.

@SimonSapin, it's a good idea, but I did not want to install another python26 in my machine...

What I did was uninstall macports completely and install homebrew. Although the problem persisted, brew link --force cairo worked for me.

Thanks very much for your help, guys.

So … suggestions for the install docs?

@pelegrini , I don’t think that the PATH env variable is relevant to shared library loading. LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, and DYLD_FALLBACK_LIBRARY_PATH are.

It worked for me setting the correct path for DYLD_LIBRARY_PATH.

DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/Cellar/cairo/1.10.2/lib/

Hi, I have just got the same issue on Mac 10.8.4.
Investigated an issue and localization gave me, that:

$ brew install cairo

- returned HTTP 404 error for glib dependency
So, I just made:

$ brew update

After that both installation of cairo and running weasyprint were fine:

$ brew install cairo pango gdk-pixbuf libxml2 libxslt libffi
$ pip install WeasyPrint
$ weasyprint --help

- worked for me

$ export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib

Fixes the issue with macports.

@jmelett thanks! This solved the issue for me and I'm still using the system python. (for many reasons I prefer to use it). I set the path and then reinstalled cairocffi with

 pip install --upgrade --force-reinstall cairoffi 

https://github.com/Kozea/WeasyPrint/issues/79#issuecomment-28835056

I can confirm that DYLD_FALLBACK_LIBRARY_PATH solution works with Python 3.4 and macports.
I could be useful to put this export into ~/.profile.

Just wanted to comment that I found this problem with Python 3.6 + MacOS High Sierra. Installed deps with brew as instructed but got similar complaints. Fixed via export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:/usr/local/lib

Was this page helpful?
0 / 5 - 0 ratings