Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError: cannot load library 'gobject-2.0-0': gobject-2.0-0: cannot open shared object file #2011

Closed
jtziebarth opened this issue Nov 30, 2023 · 9 comments

Comments

@jtziebarth
Copy link

I know this error has been posted before, but I'm encountering it under different circumstances.

System: WSL Ubuntu 20.04

Steps to reproduce:
conda create -n test python=3.10
conda activate test
pip install weasyprint
weasyprint --info

which produces:

OSError: cannot load library 'gobject-2.0-0': gobject-2.0-0: cannot open shared object file: No such file or directory. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'

Context:
For work I have different versions of python running in separate environments that I create using Miniconda and then pip install all of my dependencies. I understand the pitfalls of mixing conda and pip, but I've followed all of the precautions and it's my understanding that steps have been taken in recent history to get the two to play nicer together. Historically I haven't had issues with this approach when following said precautions.

Steps I've tried:
I've installed the packages listed under Ubuntu 20.04 in the troubleshooting docs. Additionally I've tried the suggestion offered in a related issue thread. I'm still having the issue.

Additional info:
If I install weasyprint outside the environment and run weasyprint --info outside the environment, I don't get errors. Nor do I get errors if I install weasyprint inside the environment using conda install -c conda-forge weasyprint and run weasyprint --info inside the environment.

Any idea how to succeed using the approach I've outlined in "steps to reproduce?"

@liZe
Copy link
Member

liZe commented Dec 1, 2023

Hi!

If you use Conda, you probably need to install WeasyPrint’s non-Python dependencies (at least Pango, that will install GObject) with Conda.

I understand the pitfalls of mixing conda and pip

Installing WeasyPrint with pip in Conda, on Ubuntu, on WSL, on Windows. Well… Good luck! 😄

@liZe
Copy link
Member

liZe commented Dec 4, 2023

@jtziebarth Did it work?

@jtziebarth
Copy link
Author

conda install -c anaconda pango prior to pip install weasyprint works, but that's unfortunate that there is no pure pip solution where all project dependencies can be pip installed from a requirements file.

@liZe
Copy link
Member

liZe commented Dec 5, 2023

conda install -c anaconda pango prior to pip install weasyprint works, but that's unfortunate that there is no pure pip solution where all project dependencies can be pip installed from a requirements file.

pip installs Python packages, and Pango is not a Python package. That’s exactly why package managers like Conda have been invented: conda install weasyprint works out of the box. 😀

Related to #841 and #1241.

@colaul
Copy link

colaul commented May 1, 2024

conda install -c anaconda pango prior to pip install weasyprint works, but that's unfortunate that there is no pure pip solution where all project dependencies can be pip installed from a requirements file.

Assist me

WeasyPrint could not import some external libraries. Please carefully follow the installation steps before reporting an issue:
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#troubleshooting


Traceback (most recent call last):
File "p:\Projects\zIgnorance\Subtitles app\JFK\app.py", line 14, in
from weasyprint import HTML
File "C:\Users\Collins Paul\AppData\Roaming\Python\Python312\site-packages\weasyprint_init_.py", line 419, in
from .css import preprocess_stylesheet # noqa: I001, E402
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Collins Paul\AppData\Roaming\Python\Python312\site-packages\weasyprint\css_init_.py", line 28, in
from .computed_values import COMPUTER_FUNCTIONS
File "C:\Users\Collins Paul\AppData\Roaming\Python\Python312\site-packages\weasyprint\css\computed_values.py", line 9, in
from ..text.ffi import ffi, pango, units_to_double
File "C:\Users\Collins Paul\AppData\Roaming\Python\Python312\site-packages\weasyprint\text\ffi.py", line 431, in
gobject = _dlopen(
^^^^^^^^
File "C:\Users\Collins Paul\AppData\Roaming\Python\Python312\site-packages\weasyprint\text\ffi.py", line 420, in _dlopen
return ffi.dlopen(names[0]) # pragma: no cover
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Collins Paul\AppData\Roaming\Python\Python312\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Collins Paul\AppData\Roaming\Python\Python312\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Collins Paul\AppData\Roaming\Python\Python312\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'

@liZe
Copy link
Member

liZe commented May 1, 2024

@FFED246529C6BEDED02CAEAF Did you install GTK?

@colaul
Copy link

colaul commented May 2, 2024

Yes I have gtk3-runtime-3.24.31-2022-01-04-ts-win64.exe

@liZe
Copy link
Member

liZe commented May 2, 2024

Yes I have gtk3-runtime-3.24.31-2022-01-04-ts-win64.exe

If you have GTK3 installed in the default folder, and have DLLs in C:\Program Files\GTK3-Runtime Win64\bin, everything should work. If it’s installed elsewhere, you can put the path to your GTK3’s bin folder in the WEASYPRINT_DLL_DIRECTORIES environment variable.

If you still get this error, please open a new issue.

@Djedouas
Copy link

Djedouas commented May 24, 2024

apt install weasyprint is also possible and worked for me (best solution in my environment - in python:3.12-slim docker image).

@Kozea Kozea locked as resolved and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants