如何解决 weasyprint 错误消息 gobject-2.0-0 错误 0x7e 消息?

qui*_*inn 8 python weasyprint

我根据`https://pbpython.com/pdf-reports.htm 安装了几个文件来创建报告。但是出现以下错误信息

Traceback (most recent call last):
  File "C:\histdata\test02.py", line 10, in <module>
    from weasyprint import HTML
  File "C:\Users\AquaTrader\AppData\Local\Programs\Python\Python38\lib\site-packages\weasyprint\__init__.py", line 322, in <module>
    from .css import preprocess_stylesheet  # noqa isort:skip
  File "C:\Users\AquaTrader\AppData\Local\Programs\Python\Python38\lib\site-packages\weasyprint\css\__init__.py", line 27, in <module>
    from . import computed_values, counters, media_queries
  File "C:\Users\AquaTrader\AppData\Local\Programs\Python\Python38\lib\site-packages\weasyprint\css\computed_values.py", line 16, in <module>
    from ..text.ffi import ffi, pango, units_to_double
  File "C:\Users\AquaTrader\AppData\Local\Programs\Python\Python38\lib\site-packages\weasyprint\text\ffi.py", line 380, in <module>
    gobject = _dlopen(
  File "C:\Users\AquaTrader\AppData\Local\Programs\Python\Python38\lib\site-packages\weasyprint\text\ffi.py", line 377, in _dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "C:\Users\AquaTrader\AppData\Local\Programs\Python\Python38\lib\site-packages\cffi\api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "C:\Users\AquaTrader\AppData\Local\Programs\Python\Python38\lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "C:\Users\AquaTrader\AppData\Local\Programs\Python\Python38\lib\site-packages\cffi\api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: cannot load library 'gobject-2.0-0': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'
Run Code Online (Sandbox Code Playgroud)

有什么建议么?提前致谢。(请注意,github 上有一个类似的问题,告诉个人安装 GTK3。)这是正确的吗?

mad*_*mad 7

该错误意味着gobject-2.0.0无法找到作为 GTK3+ 一部分的库。您是否按照安装说明(https://doc.courtbouillon.org/weasyprint/stable/first_steps.html)进行操作,其中包括 GTK3+ 的安装?如果没有,就这样做。如果是,那么问题是 GTK3+ DLL 不是 Python 正在寻找的地方。为此,您需要将包含 DLL 的目录(例如C:\Program Files\GTK3-Runtime Win64\bin在 Windows 上)添加到 PATH 环境变量中。该目录包含相关的libgobject-2.0-0.dll库。

WEASYPRINT_DLL_DIRECTORIES对于 Python 3.8+ 和 weasyprint 54+,您可以使用环境变量(文档)手动设置 GTK3+ 库的路径。