加载DLL时,Python CFFI模块失败:OSError 0x7e

时间:2013-11-24 11:38:51

标签: python windows dll python-cffi

我在Windows 7,64位下运行Python 3.3(Anaconda发行版)。我曾尝试安装Weasyprint应用程序/库,它有许多依赖项,包括CFFI,我必须从源代码编译,因为在二进制发行版中没有可用的兼容版本。

当我运行weasyprint时,它会在导入加载过程中窒息,特别是当它调用CFFI以便为Cairo加载GTK +库dll时。我得到的错误如下:

$ 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 

我所拥有的环境如下:Windows 7.1 64位,Python 3.3 64位,CFFI编译(由我)在64位环境的Visual Studio 2010下,以及Cairo的libcairo-2.dll也在64位位版。

我不是Windows程序员,我只是钻研这个烂摊子因为我想让Weasyprint为另一个(Python语言)项目工作。很久以前我在Delphi下做过一点点的Windows编程,所以我对这些东西的工作原理模糊不清,但我一直无法解决这个问题。

2 个答案:

答案 0 :(得分:1)

我遇到了类似的错误(冲突的DLL),最终只是通过将路径移动到GTK(例如:&#34; C:\ gtk \ bin&#34;)到环境变量的开头来解决它。 / p>

答案 1 :(得分:0)

对我来说,安装GTK +无效。 我使用section adornments style解决了这个问题。 我的环境是

  • Python 3.7
  • Windows 10 x64
  1. 安装UniConverter2.0
  2. 在UniConverter安装路径下找到“ dll”子目录。(在我的情况下为C:\Program Files\UniConvertor-2.0rc4\dlls
  3. 将此“ dll”路径添加到系统路径。
  4. 关闭VSCode(或其他),然后重新打开项目。
  5. 尝试再次运行代码。 享受吧!