'how to solve weasyprint error message gobject-2.0-0 error 0x7e message?

I installed several files based upon `https://pbpython.com/pdf-reports.htm to create reports. However the following error messages

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'

Any suggestions? Thanks in advance. (Please note that there is a similar issue on github which tells the individual to install GTK3.) Is this correct?



Solution 1:[1]

The error means that the gobject-2.0.0 library, which is part of GTK3+, cannot be found. Did you follow the installation instructions (https://doc.courtbouillon.org/weasyprint/stable/first_steps.html), which include installation of GTK3+? If no, do that. If yes, then the problem is, that the GTK3+ DLLs are not where Python is looking for them. For this, you need to add the directory containing the DLLs (e.g. C:\Program Files\GTK3-Runtime Win64\bin on Windows) to your PATH environment variable. That directory contains the relevant libgobject-2.0-0.dll library.

For Python 3.8+ and weasyprint 54+ you can manually set the path to your GTK3+ library with the environment variable WEASYPRINT_DLL_DIRECTORIES (documentation).

Solution 2:[2]

As @mad said, you need the GTK3 library to have the libobject-2.0.0 DLL. In Github Actions for example, you might be interested to use the tschoonj/GTK-for-Windows repository :

# 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 += "$PWD\gtk-nsis-pack\bin"

# Add it to GitHub Actions PATH
# echo "$PWD\gtk-nsis-pack\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 secavfr