Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python CFFI module fails when loading dll: OSError 0x7e

I run Python 3.3 (Anaconda distribution) under Windows 7, 64-bit. I have attempted to install the Weasyprint app/library, which has a number of dependencies, including CFFI, which I had to compile from source because no compatible version of it was available in a binary distribution.

When I run weasyprint, it chokes during the import loading process, specifically when it calls CFFI in order to load the GTK+ library dll for Cairo. The error that I get is as follows:

$ weasyprint
Traceback (most recent call last):
  File "c:\anaconda\envs\py33\lib\site-packages\cffi-0.8-py3.3-win-amd64.egg\cffi\api.py", line 399, in _make_ffi_library
    backendlib = backend.load_library(name, flags)
OSError: cannot load library libcairo-2.dll: error 0x7e

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Anaconda\envs\py33\Scripts\weasyprint-script.py", line 9, in <module>
    load_entry_point('WeasyPrint==0.20', 'console_scripts', 'weasyprint')()
  File "C:\Anaconda\envs\py33\lib\site-packages\pkg_resources.py", line 343, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "C:\Anaconda\envs\py33\lib\site-packages\pkg_resources.py", line 2355, in load_entry_point
    return ep.load()
  File "C:\Anaconda\envs\py33\lib\site-packages\pkg_resources.py", line 2061, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "c:\anaconda\envs\py33\lib\site-packages\weasyprint-0.20-py3.3.egg\weasyprint\__init__.py", line 309, in <module>
    from .css import PARSER, preprocess_stylesheet
  File "c:\anaconda\envs\py33\lib\site-packages\weasyprint-0.20-py3.3.egg\weasyprint\css\__init__.py", line 30, in <module>
    from . import computed_values
  File "c:\anaconda\envs\py33\lib\site-packages\weasyprint-0.20-py3.3.egg\weasyprint\css\computed_values.py", line 18, in <module>
    from .. import text
  File "c:\anaconda\envs\py33\lib\site-packages\weasyprint-0.20-py3.3.egg\weasyprint\text.py", line 18, in <module>
    import cairocffi as cairo
  File "c:\anaconda\envs\py33\lib\site-packages\cairocffi-0.5.1-py3.3.egg\cairocffi\__init__.py", line 39, in <module>
    cairo = dlopen(ffi, 'libcairo-2.dll', 'cairo', 'libcairo-2')
  File "c:\anaconda\envs\py33\lib\site-packages\cairocffi-0.5.1-py3.3.egg\cairocffi\__init__.py", line 34, in dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "c:\anaconda\envs\py33\lib\site-packages\cffi-0.8-py3.3-win-amd64.egg\cffi\api.py", line 117, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "c:\anaconda\envs\py33\lib\site-packages\cffi-0.8-py3.3-win-amd64.egg\cffi\api.py", line 405, in _make_ffi_library
    backendlib = backend.load_library(path, flags)
OSError: cannot load library C:\Windows\system32\libcairo-2.dll: error 0x7e 

The environment I have is as follows: Windows 7.1 64-bit, Python 3.3 64 bit, CFFI compiled (by me) under Visual Studio 2010 with a 64-bit environment, and Cairo's libcairo-2.dll also in a 64-bit version.

I am not a Windows programmer, and am only delving into this mess because I want to get Weasyprint to work for another (Python language) project. I have done a minor bit of Windows programming a long time ago under Delphi, so I have a vague grasp of how this stuff works, but I have been unable to solve this problem.

like image 910
Erik Norvelle Avatar asked Nov 24 '13 11:11

Erik Norvelle


1 Answers

I was getting similar errors (conflicting DLLs) and it was finally resolved simply by moving the path to GTK (ex: "C:\gtk\bin") to the beginning of my environment variables.

like image 62
Mike S Avatar answered Sep 27 '22 16:09

Mike S