conda-forge / weasyprint-feedstock

A conda-smithy repository for weasyprint.
BSD 3-Clause "New" or "Revised" License
2 stars 4 forks source link

OSError: cannot load library 'gobject-2.0' #23

Closed Keou0007 closed 3 years ago

Keou0007 commented 3 years ago

Issue:

Recently weasyprint stopped importing for me with the error:

OSError: cannot load library 'gobject-2.0': dlopen(gobject-2.0, 2): image not found.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0'

I wasn't sure if it was something I changed, so I tried going back to basics. With a brand new installation of miniconda:

conda create -n weasyprint python=3.8
conda activate weasyprint
conda install -y -c conda-forge weasyprint
python -c 'import weasyprint'

I still get the OSError. Any ideas?


Environment (conda list):

``` $ conda list # packages in environment at /Users/shannon/opt/miniconda3/envs/weasyprint: # # Name Version Build Channel ca-certificates 2021.5.30 h033912b_0 conda-forge cairo 1.16.0 he43a7df_1008 conda-forge cairocffi 1.2.0 pyhd8ed1ab_0 conda-forge cairosvg 2.5.2 pyhd8ed1ab_0 conda-forge certifi 2021.5.30 py38h50d1736_0 conda-forge cffi 1.14.5 py38ha97d567_0 conda-forge cssselect2 0.2.1 pyh9f0ad1d_1 conda-forge defusedxml 0.7.1 pyhd8ed1ab_0 conda-forge font-ttf-dejavu-sans-mono 2.37 hab24e00_0 conda-forge font-ttf-inconsolata 3.000 h77eed37_0 conda-forge font-ttf-source-code-pro 2.038 h77eed37_0 conda-forge font-ttf-ubuntu 0.83 hab24e00_0 conda-forge fontconfig 2.13.1 h10f422b_1005 conda-forge fonts-conda-ecosystem 1 0 conda-forge fonts-conda-forge 1 0 conda-forge freetype 2.10.4 h4cff582_1 conda-forge fribidi 1.0.10 hbcb3906_0 conda-forge gdk-pixbuf 2.42.6 h2e6141f_0 conda-forge gettext 0.19.8.1 h7937167_1005 conda-forge graphite2 1.3.13 h2e338ed_1001 conda-forge harfbuzz 2.8.1 h159f659_0 conda-forge html5lib 1.1 pyh9f0ad1d_0 conda-forge icu 68.1 h74dc148_0 conda-forge jbig 2.1 h0d85af4_2003 conda-forge jpeg 9d hbcb3906_0 conda-forge lcms2 2.12 h577c468_0 conda-forge lerc 2.2.1 h046ec9c_0 conda-forge libcxx 11.1.0 habf9029_0 conda-forge libdeflate 1.7 h35c211d_5 conda-forge libffi 3.3 h046ec9c_2 conda-forge libglib 2.68.3 hd556434_0 conda-forge libiconv 1.16 haf1e3a3_0 conda-forge libpng 1.6.37 h7cec526_2 conda-forge libtiff 4.3.0 h1167814_1 conda-forge libwebp-base 1.2.0 h0d85af4_2 conda-forge libxml2 2.9.12 h93ec3fd_0 conda-forge lz4-c 1.9.3 h046ec9c_0 conda-forge ncurses 6.2 h2e338ed_4 conda-forge olefile 0.46 pyh9f0ad1d_1 conda-forge openjpeg 2.4.0 h6e7aa92_1 conda-forge openssl 1.1.1k h0d85af4_0 conda-forge pango 1.48.5 ha05cd14_0 conda-forge pcre 8.44 hb1e8313_0 conda-forge pillow 8.2.0 py38h83525de_1 conda-forge pip 21.1.2 pyhd8ed1ab_0 conda-forge pixman 0.40.0 hbcb3906_0 conda-forge pycparser 2.20 pyh9f0ad1d_2 conda-forge pyphen 0.10.0 pyhd8ed1ab_0 conda-forge python 3.8.10 h0e5c897_0_cpython conda-forge python_abi 3.8 1_cp38 conda-forge readline 8.1 h05e3726_0 conda-forge setuptools 49.6.0 py38h50d1736_3 conda-forge six 1.16.0 pyh6c4a22f_0 conda-forge sqlite 3.35.5 h44b9ce1_0 conda-forge tinycss2 1.1.0 pyhd8ed1ab_0 conda-forge tk 8.6.10 h0419947_1 conda-forge weasyprint 52.5 pyhd8ed1ab_0 conda-forge webencodings 0.5.1 py_1 conda-forge wheel 0.36.2 pyhd3deb0d_0 conda-forge xz 5.2.5 haf1e3a3_1 conda-forge zlib 1.2.11 h7795811_1010 conda-forge zstd 1.5.0 h582d3a0_0 conda-forge ```


Details about conda and system ( conda info ):

``` $ conda info active environment : weasyprint active env location : /Users/shannon/opt/miniconda3/envs/weasyprint shell level : 2 user config file : /Users/shannon/.condarc populated config files : /Users/shannon/.condarc conda version : 4.10.1 conda-build version : not installed python version : 3.8.10.final.0 virtual packages : __osx=10.16=0 __unix=0=0 __archspec=1=x86_64 base environment : /Users/shannon/opt/miniconda3 (writable) conda av data dir : /Users/shannon/opt/miniconda3/etc/conda conda av metadata url : https://repo.anaconda.com/pkgs/main channel URLs : https://conda.anaconda.org/conda-forge/osx-64 https://conda.anaconda.org/conda-forge/noarch https://repo.anaconda.com/pkgs/main/osx-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/osx-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /Users/shannon/opt/miniconda3/pkgs /Users/shannon/.conda/pkgs envs directories : /Users/shannon/opt/miniconda3/envs /Users/shannon/.conda/envs platform : osx-64 user-agent : conda/4.10.1 requests/2.25.1 CPython/3.8.10 Darwin/20.5.0 OSX/10.16 UID:GID : 501:20 netrc file : None offline mode : False ```
BastianZim commented 3 years ago

Can you try it with just cairo instead of weasyprint in the environment? gobject-2.0 shouldn't be a direct dependency of weasyprint but rather cairo.

Edit: The full traceback would also be helpful in finding whether this is because of weasyprint or cairo.

Keou0007 commented 3 years ago

Trying with just cairo now. The full traceback is

$ python -c "import weasyprint"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/shannon/opt/miniconda3/envs/weasyprint/lib/python3.6/site-packages/weasyprint/__init__.py", line 469, in <module>
    from .css import preprocess_stylesheet  # noqa isort:skip
  File "/Users/shannon/opt/miniconda3/envs/weasyprint/lib/python3.6/site-packages/weasyprint/css/__init__.py", line 27, in <module>
    from . import computed_values, counters, media_queries
  File "/Users/shannon/opt/miniconda3/envs/weasyprint/lib/python3.6/site-packages/weasyprint/css/computed_values.py", line 15, in <module>
    from .. import text
  File "/Users/shannon/opt/miniconda3/envs/weasyprint/lib/python3.6/site-packages/weasyprint/text.py", line 259, in <module>
    'libgobject-2.0.dylib')
  File "/Users/shannon/opt/miniconda3/envs/weasyprint/lib/python3.6/site-packages/weasyprint/text.py", line 255, in dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "/Users/shannon/opt/miniconda3/envs/weasyprint/lib/python3.6/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/Users/shannon/opt/miniconda3/envs/weasyprint/lib/python3.6/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/Users/shannon/opt/miniconda3/envs/weasyprint/lib/python3.6/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: cannot load library 'gobject-2.0': dlopen(gobject-2.0, 2): image not found.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0'
Keou0007 commented 3 years ago

This works fine

conda create -n cairo python=3.8 cairo pycairo
conda activate cairo
python -c "import cairo"
BastianZim commented 3 years ago

Hmm ok then it's something else. Did you install everything through conda? Because I can find some other issues like this but it was primarily because parts were installed not through conda but homebrew etc.

Keou0007 commented 3 years ago

yeah everything should be installed via conda. I do have homebrew on my system and that probably has a python install, but I've not had any conflicts between them before. Weasyprint had been working just fine for me. Last time I used it successfully was about two weeks ago. Not sure what I did that broke it, but I suspect conda update --all

BastianZim commented 3 years ago

Not completely sure about that because I have the same setup and cannot reproduce the error. What kind of paths do you have on your system?

python -c "import os; print(*os.environ['PATH'].split(os.pathsep), sep='\n')"
Keou0007 commented 3 years ago
/Users/shannon/opt/miniconda3/bin
/Users/shannon/opt/miniconda3/condabin
/opt/local/bin
/opt/local/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin
/Applications/Little Snitch.app/Contents/Components
/opt/X11/bin
/Library/Apple/usr/bin
/Library/Frameworks/Mono.framework/Versions/Current/Commands
/usr/local/git/bin
BastianZim commented 3 years ago

Did you run that in the environment? Because I have an environment-specific path first.

Keou0007 commented 3 years ago

sorry, I didn't

/Users/shannon/opt/miniconda3/envs/weasyprint/bin
/Users/shannon/opt/miniconda3/bin
/Users/shannon/opt/miniconda3/condabin
/opt/local/bin
/opt/local/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin
/Applications/Little Snitch.app/Contents/Components
/opt/X11/bin
/Library/Apple/usr/bin
/Library/Frameworks/Mono.framework/Versions/Current/Commands
/usr/local/git/bin
BastianZim commented 3 years ago

Ok that looks exactly like mine - strange. Updating all does change the environment but then shouldn't really affect the individual components again. The only thing I can think of is installing gtk3 directly (conda install -c conda-forge gtk3) as suggested here: https://github.com/Kozea/WeasyPrint/issues/971

Keou0007 commented 3 years ago

yeah I already tried that, as well as any other glib things I could find, before I posted the issue. I'm really run out of ideas here.

BastianZim commented 3 years ago

Mine is under '/usr/local/lib/libgobject-2.0.dylib'. Is this empty for you?

Keou0007 commented 3 years ago

yup

$ ls /usr/local/lib/libg*
/usr/local/lib/libgcc_s.1.dylib     /usr/local/lib/libgdbm.a        /usr/local/lib/libgdbm_compat.4.dylib   /usr/local/lib/libgdbm_compat.dylib /usr/local/lib/libgraphite2.3.dylib
/usr/local/lib/libgdbm.6.dylib      /usr/local/lib/libgdbm.dylib        /usr/local/lib/libgdbm_compat.a     /usr/local/lib/libgraphite2.3.2.1.dylib /usr/local/lib/libgraphite2.dylib
Keou0007 commented 3 years ago

hmmm. I just did conda install glib in that environment and that seems to have fixed it. I'm SURE I tried that before...

BastianZim commented 3 years ago

Haha just wanted to ask that. Ok then it's a missing dependency.

BastianZim commented 3 years ago

Ok that's a conda error because libglib should've installed that.

Edit: It's just run_constrained, I'll open an issue.

BastianZim commented 3 years ago

@liZe Do you know where the glib dependency is from? And is there a minimum version? If it's really required, I'd just add it to the meta.yaml.

liZe commented 3 years ago

@liZe Do you know where the glib dependency is from? And is there a minimum version? If it's really required, I'd just add it to the meta.yaml.

Isn’t libgobject-2.0.dylib supposed to be provided by libglib (that was already installed, probably as a dependency of Cairo)?

BastianZim commented 3 years ago

Isn’t libgobject-2.0.dylib supposed to be provided by libglib (that was already installed, probably as a dependency of Cairo)?

Yes and there‘s probably something wrong there: https://github.com/conda-forge/glib-feedstock/issues/104

This was just as a preliminary fix until then but it’s also probably fine to just wait and keep the issue open until then.

liZe commented 3 years ago

Yes and there‘s probably something wrong there: conda-forge/glib-feedstock#104

OK

This was just as a preliminary fix until then but it’s also probably fine to just wait and keep the issue open until then.

Adding the dependency with a comment linked to the issue is a possible workaround for now.