Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError: cannot load library 'libxcb.dylib': dlopen(libxcb.dylib, 2): image not found #475

Closed
danielterwiel opened this issue Jun 14, 2017 · 4 comments

Comments

@danielterwiel
Copy link

danielterwiel commented Jun 14, 2017

I'm running the latest version of Mac OS Sierra: 10.12.5 (16F73) and got the latest Python: 3.6.1 running when I install my dependencies using pip3.

Furthermore I've got the whole shebang of dependencies installed through homebrew:

brew install cairo pango gdk-pixbuf libxml2 libxslt libffi

However, when I install weasyprint through pip I keep getting the following error:

Collecting cairocffi>=0.5 (from WeasyPrint==0.36->-r requirements/base.txt (line 40))
  Using cached cairocffi-0.8.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/j6/jz01n57d5hs3z3k6442cd9xr0000gn/T/pip-build-9n8h9jja/cairocffi/setup.py", line 44, in <module>
        extras_require={'xcb': ['xcffib>=0.3.2']},
      File "/Users/dani/.pyenv/versions/3.6.1/lib/python3.6/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/Users/dani/.pyenv/versions/3.6.1/envs/project/lib/python3.6/site-packages/setuptools/dist.py", line 321, in __init__
        _Distribution.__init__(self, attrs)
      File "/Users/dani/.pyenv/versions/3.6.1/lib/python3.6/distutils/dist.py", line 281, in __init__
        self.finalize_options()
      File "/Users/dani/.pyenv/versions/3.6.1/envs/project/lib/python3.6/site-packages/setuptools/dist.py", line 390, in finalize_options
        ep.load()(self, ep.name, value)
      File "/Users/dani/.pyenv/versions/3.6.1/envs/project/lib/python3.6/site-packages/cffi/setuptools_ext.py", line 188, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "/Users/dani/.pyenv/versions/3.6.1/envs/project/lib/python3.6/site-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "/Users/dani/.pyenv/versions/3.6.1/envs/project/lib/python3.6/site-packages/cffi/setuptools_ext.py", line 25, in execfile
        exec(code, glob, glob)
      File "cairocffi/ffi_build.py", line 32, in <module>
        from xcffib.ffi_build import ffi as xcb_ffi
      File "/Users/dani/.pyenv/versions/3.6.1/envs/project/lib/python3.6/site-packages/xcffib/__init__.py", line 34, in <module>
        lib = ffi.dlopen(soname)
    OSError: cannot load library 'libxcb.dylib': dlopen(libxcb.dylib, 2): image not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/j6/jz01n57d5hs3z3k6442cd9xr0000gn/T/pip-build-9n8h9jja/cairocffi/

I'm not sure how to proceed, but it seems like WeazsyPrint is not able to find libxcb, which seems to be a dependency of cairo if I'm not mistaken. cairo is really installed through homebrew. When I perform a locate libxcb.dylib I only come across /opt/X11/lib/libxcb.dylib, which comes from Quartz.

I haven't came across people with the exact same issue so I decided to leave a ticket.

@danielterwiel
Copy link
Author

danielterwiel commented Jun 14, 2017

Not sure if it is even remotely useful, but I've managed to get the installation working. But now it's failing at runtime. What I did was setting the DYLD_FALLBACK_LIBRARY_PATH variable to the Quartz library folder:

export DYLD_FALLBACK_LIBRARY_PATH=/opt/X11/lib/

and after that I followed https://stackoverflow.com/questions/37437041/dlopen-failed-to-load-a-library-cairo-cairo-2 :

export DYLD_LIBRARY_PATH=/usr/local/Cellar/cairo/1.14.8/lib/:/usr/local/Cellar/glib/2.52.2/lib/:/usr/local/Cellar/pango/1.40.6/lib/

and https://coderwall.com/p/-k_93g/mac-os-x-valueerror-unknown-locale-utf-8-in-python:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Now WeasyPrint installs through pip flawlessly, however I keep getting te following error during runtime:

(project) danis-MacBook-Pro:project dani$ python project/manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x111ef1950>
Traceback (most recent call last):
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/django/utils/autoreload.py", line 250, in raise_last_exception
    six.reraise(*_exception)
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models()
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/dani/.pyenv/versions/3.6.1/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/Users/dani/dev/project/project/assets/models.py", line 9, in <module>
    import core.utils
  File "/Users/dani/dev/project/project/core/utils.py", line 22, in <module>
    import tasks.models
  File "/Users/dani/dev/project/project/tasks/models.py", line 16, in <module>
    import ive.tasks
  File "/Users/dani/dev/project/project/ive/tasks.py", line 16, in <module>
    import ive.utils
  File "/Users/dani/dev/project/project/ive/utils.py", line 20, in <module>
    from reports.tasks import report_generator
  File "/Users/dani/dev/project/project/reports/tasks.py", line 17, in <module>
    from weasyprint import HTML, CSS
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/weasyprint/__init__.py", line 361, in <module>
    from .css import PARSER, preprocess_stylesheet  # noqa
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/weasyprint/css/__init__.py", line 30, in <module>
    from . import computed_values
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/weasyprint/css/computed_values.py", line 18, in <module>
    from .. import text
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/weasyprint/text.py", line 20, in <module>
    import cairocffi as cairo
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/cairocffi/__init__.py", line 18, in <module>
    from ._ffi import ffi
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/cairocffi/_ffi.py", line 3, in <module>
    from xcffib._ffi import ffi as _ffi0
  File "/Users/dani/.pyenv/versions/project/lib/python3.6/site-packages/xcffib/__init__.py", line 34, in <module>
    lib = ffi.dlopen(soname)
OSError: cannot load library 'libxcb.dylib': dlopen(libxcb.dylib, 2): image not found

@liZe
Copy link
Member

liZe commented Jun 14, 2017

Thank you for taking the time to report this issue.

Setting the DYLD_FALLBACK_LIBRARY_PATH variable when launching your Python script (as you did with pip) should do the trick.

Another solution is to remove the xcffib Python module, as it's probably not needed for WeasyPrint.

I don't know what's going on with MacOS libraries, you'll find many bugs like this one (#277, #79, Kozea/cairocffi#28…). We've already spend a lot of time trying to find the reason of this issue, we've even automated installation on TravisCI. The only solutions we've got so far are "just set this random variable and launch this random command, I don't know why but it works for me". I'm a bit sad about that.

If anyone finds the reason why this issue appears here but not on Travis, I'd be glad to know it and definitely close these issues.

@danielterwiel
Copy link
Author

@liZe I cannot thank you enough!! pip uninstall xcffib did the trick, it doesn't seem to be needed indeed.

Thanks!!

@liZe
Copy link
Member

liZe commented Jun 14, 2017

pip uninstall xcffib did the trick, it doesn't seem to be needed indeed.

Good to know 😄.

I close this issue as it's another way to solve this issue, even if we don't know the real reason. If anyone finds a reason why this happens, please tell us!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants