- Windows 10/11 (64-bit)
- Python 3.8.10 (32-bit)
- Thonny 4.0.2
I have installed Thonny, then moved the Thonny file to a USB to make it portable.
I installed weasyprint via Thonny's manage packages window.
From weasyprint's documentation under Missing Library
Running the following code:
from weasyprint import HTML, CSS
html = HTML(string='<h1>Hello World!</h1>')
css = CSS(string='@page { size: A3; margin: 1cm }')
html.write_pdf(r'F:\weasyprint_test.pdf', stylesheets=[css])
Output from code:
Traceback (most recent call last):
File "F:\Python\test_file.py", line 3, in <module>
from weasyprint import HTML, CSS
File "F:\Thonny\lib\site-packages\weasyprint\__init__.py", line 341, in <module>
from .css import preprocess_stylesheet # noqa isort:skip
File "F:\Thonny\lib\site-packages\weasyprint\css\__init__.py", line 25, in <module>
from . import computed_values, counters, media_queries
File "F:\Thonny\lib\site-packages\weasyprint\css\computed_values.py", line 11, in <module>
from ..text.ffi import ffi, pango, units_to_double
File "F:\Thonny\lib\site-packages\weasyprint\text\ffi.py", line 428, in <module>
gobject = _dlopen(
File "F:\Thonny\lib\site-packages\weasyprint\text\ffi.py", line 417, in _dlopen
return ffi.dlopen(names[0]) # pragma: no cover
File "F:\Thonny\lib\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "F:\Thonny\lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "F:\Thonny\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'
I have tried:
After downloading and running GTK3.exe I added the \bin file from GTK3 to PATH. Then ran the same code in VSCode (Windows10) and it worked, but I can't get it to work with Thonny.
With Thonny. I have tried dragging the GTK3 complete file and the individual \bin file from GTK3 to F:\Thonny\Lib\site-packages.
I have tried adding the 'gobject-2.0-0.dll' or 'libgobject-2.0-0.dll' to F:\Thonny, F:\Thonny\Lib\site-packages, and other places in to no avail.
I have tried in using Thonny's manage packages window and clicking the 'Install from local file' with a .zip file. It installs it to F:\Thonny\user_data\plugins\Python38\site-packages and didn't work.
I have tried adding the following to the code (both the full GTK3 file location and the \bin file location with in the GTK3 file.:
import os
os.add_dll_directory(GTK3_file_location)
import sys
sys.path.append(<GTK3_file_location>)