7

我在 64 位 Windows 7 下运行 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在Visual Studio 2010下编译(由我),64位环境,开罗的libcairo-2.dll也是64位版本.

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

4

2 回答 2

2

我遇到了类似的错误(DLL 冲突),最终只需将 GTK 的路径(例如:“C:\gtk\bin”)移动到我的环境变量的开头即可解决。

于 2014-07-17T02:00:18.130 回答
0

安装 GTK+ 对我不起作用。我使用UniConverter2.0解决了这个问题。我的环境是

  • 蟒蛇 3.7
  • 视窗 10 x64
  1. 安装uniconvertor-2.0rc4-win64_headless.msi ,
  2. 找到UniConverter安装路径下的“dll”子目录。(在我的情况下,C:\Program Files\UniConvertor-2.0rc4\dlls
  3. 将此“dll”路径添加到系统路径。
  4. 关闭 VSCode(或其他)并重新打开项目。
  5. 尝试再次运行您的代码。享受!
于 2020-07-13T02:50:08.580 回答