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

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

Closed
marvinmirtschin opened this issue Jan 7, 2016 · 16 comments
Closed

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

marvinmirtschin opened this issue Jan 7, 2016 · 16 comments

Comments

@marvinmirtschin
Copy link

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\cairosvg\surface\__init__.py", line 25, in <module>
    import cairocffi as cairo
  File "C:\Python34\lib\site-packages\cairocffi\__init__.py", line 46, in <module>
    cairo = dlopen(ffi, 'cairo', 'cairo-2')
  File "C:\Python34\lib\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

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\marvin.mirtschin\Documents\cairotest.py", line 1, in <module>
    import cairosvg
  File "C:\Python34\lib\site-packages\cairosvg\__init__.py", line 27, in <module>
    from . import surface
  File "C:\Python34\lib\site-packages\cairosvg\surface\__init__.py", line 30, in <module>
    import cairo  # pycairo
ImportError: No module named 'cairo'

I read in an issue before, you can you cairocffi or pycairo but cffi seems not to work for me.

@liZe
Copy link
Member

liZe commented Jan 7, 2016

Looks like you don't have cairo installed.

As explained on the cairo download page, the official way to install cairo seems to be to install Gtk+.

They are currently different Gtk+ installers, such as:

@marvinmirtschin
Copy link
Author

Thanks a lot !

@liZe
Copy link
Member

liZe commented Jan 9, 2016

@marvinmirtschin Just for the record, which version of the installer did you use?

@marvinmirtschin
Copy link
Author

I used the GTK2-Runtime installer.
It's the one you get to from https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer

@zhaojigang
Copy link

@marvinmirtschin I meet the same error
"OSError: dlopen() failed to load a library: cairo / cairo-2"
How did you solve it?

@liZe
Copy link
Member

liZe commented Oct 6, 2016

Correctly installing Cairo on Windows is a nightmare. Being careful about 32/64bit seems to be important. You can follow very carefully the steps of the WeasyPrint documentation and see if it helps.

@bzamecnik
Copy link

On OS X (eg. El Capitan) this helped me:

export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:/usr/local/lib

@gclsoft
Copy link

gclsoft commented Aug 20, 2017

@liZe I've installed gtk, and add C:\Work2\msys64\mingw64\bin to the PATH. But still OSError: dlopen() failed to load a library: cairo / cairo-2

@gclsoft
Copy link

gclsoft commented Aug 21, 2017

I've installed https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer and set PATH. But still failed at OSError: dlopen() failed to load a library: cairo / cairo-2

@liZe
Copy link
Member

liZe commented Aug 21, 2017

@gclsoft There's nothing more I can say that's not said in the documentation. Please remove all the versions of Python and Cairo installed on your system and follow the steps, not mixing 32/64bit packages.

@MarcG046
Copy link

I had also Inkscape installed which has its own libcairo-2.dll and appeared before GTK in the PATH
(discovered it by debugging through cairocffi_init_.py)
Changing the order in the PATH 'solved' it for me.

@kinkoazc
Copy link

Yup, make sure the Python<->GTK archs match up.

@apacha
Copy link

apacha commented Jan 31, 2018

If you think, you've installed everything correctly, you can verify this, but running

import ctypes.util
ctypes.util.find_library('cairo')
ctypes.util.find_library('cairo-2')
ctypes.util.find_library('libcairo-2')

And see, which one has the correct path. If only libcairo-2 has the correct path, you might have to edit %PYTHON_HOME%\Lib\site-packages\cairocffi\__init__.py and add 'libcairo-2' into that list. At least, this fixed the problem for me.

Edit: Installing cairo for Python is probably easiest, if you install it via conda install cairo

@sega97
Copy link

sega97 commented Feb 14, 2018

On Win7, changing the order in the PATH 'solved' it for me. Put the GTK path before Python path.

@marius778
Copy link

I did execute, recommended by a user above.

export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:/usr/local/lib

How can I reverse it?

Thanks

@johncrosby
Copy link

This helped me on a mac: https://weasyprint.readthedocs.io/en/stable/install.html#macos

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