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



我基于' https://pbpython.com/pdf-reports.htm安装了几个文件来创建报表。但是下面的错误消息

Traceback (most recent call last):
File "C:histdatatest02.py", line 10, in <module>
from weasyprint import HTML
File "C:UsersAquaTraderAppDataLocalProgramsPythonPython38libsite-packagesweasyprint__init__.py", line 322, in <module>
from .css import preprocess_stylesheet  # noqa isort:skip
File "C:UsersAquaTraderAppDataLocalProgramsPythonPython38libsite-packagesweasyprintcss__init__.py", line 27, in <module>
from . import computed_values, counters, media_queries
File "C:UsersAquaTraderAppDataLocalProgramsPythonPython38libsite-packagesweasyprintcsscomputed_values.py", line 16, in <module>
from ..text.ffi import ffi, pango, units_to_double
File "C:UsersAquaTraderAppDataLocalProgramsPythonPython38libsite-packagesweasyprinttextffi.py", line 380, in <module>
gobject = _dlopen(
File "C:UsersAquaTraderAppDataLocalProgramsPythonPython38libsite-packagesweasyprinttextffi.py", line 377, in _dlopen
return ffi.dlopen(names[0])  # pragma: no cover
File "C:UsersAquaTraderAppDataLocalProgramsPythonPython38libsite-packagescffiapi.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:UsersAquaTraderAppDataLocalProgramsPythonPython38libsite-packagescffiapi.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:UsersAquaTraderAppDataLocalProgramsPythonPython38libsite-packagescffiapi.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'

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

无法找到GTK3+的gobject-2.0.0库。您是否遵循了安装说明(https://doc.courtbouillon.org/weasyprint/stable/firstrongteps.html),其中包括GTK3+的安装?如果没有,就这样做。如果是,那么问题是,GTK3+ dll不在Python寻找它们的地方。为此,您需要将包含dll的目录(例如Windows上的C:Program FilesGTK3-Runtime Win64bin)添加到PATH环境变量中。

libgobject-2.0-0.dll库目录

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

InstallGTK-for-Windows-Runtime-Environment-Installer来自:

https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases

正如@mad所说,您需要GTK3库来拥有libobject-2.0.0DLL。例如,在Github Actions中,您可能有兴趣使用tschoonj/gtk -for windows存储库:

# Download GTK3 resources
git clone -b 2022-01-04 https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer GTK
cd GTK
# Add it to classic Windows install PATH
$Env:PATH += "$PWDgtk-nsis-packbin"
# Add it to GitHub Actions PATH
# echo "$PWDgtk-nsis-packbin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

相关内容

最新更新