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': error 0x7e #1556

Closed
jancoow opened this issue Jan 31, 2022 · 21 comments
Closed

OSError: cannot load library 'gobject-2.0-0': error 0x7e #1556

jancoow opened this issue Jan 31, 2022 · 21 comments

Comments

@jancoow
Copy link

jancoow commented Jan 31, 2022

Hi,

I'm trying to install weasyprint on Windows, but I'm unable to. On Linux it's working fine.
I'm getting this error:

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've installed gtk3-runtime according the documentation but it's unable to find the bin directory. I've tried both python3.7 as python3.8 with no luck.

@zhangkaizhao
Copy link

I've met a similar issue on macOS x86_64 in a pure virtualenv environment.

pip install weasyprint
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting weasyprint
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/cf/af/a4dc61c5b74eecec5daa9aa4e82c80248e30a54a5f5f4650a8e631651c54/weasyprint-54.0-py3-none-any.whl (247 kB)
Collecting tinycss2>=1.0.0
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/53/7b/5dba39bf0572f1f28e2844f08f74a73482a381de1d1feac3bbc6b808051e/tinycss2-1.1.1-py3-none-any.whl (21 kB)
Collecting Pillow>=4.0.0
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e1/91/b50b616b77fd6a3ab46e6a4724e07c898a5172cb8f4faf5b3b6f3c7aa17a/Pillow-9.0.0-cp38-cp38-macosx_10_10_x86_64.whl (3.0 MB)
Collecting cssselect2>=0.1
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/99/da/c86ec74495c69518720652f8aa8ab642d8af61a2098eede9db8b03d3c8b4/cssselect2-0.4.1-py3-none-any.whl (13 kB)
Collecting pydyf>=0.0.3
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/dd/53/a7e58d2e91cdab7ee0c314a4f55849241d89f84d8c92fbee39ce381c0e57/pydyf-0.1.2-py3-none-any.whl (6.4 kB)
Collecting fonttools[woff]>=4.0.0
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/1b/1e/23df4eda86938b503698c24f100462f6e80a8b40094635284e57994722ac/fonttools-4.29.0-py3-none-any.whl (895 kB)
Collecting html5lib>=1.1
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/6c/dd/a834df6482147d48e225a49515aabc28974ad5a4ca3215c18a882565b028/html5lib-1.1-py2.py3-none-any.whl (112 kB)
Collecting cffi>=0.6
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/5e/f0/693b6c7fea52d1afad55d1bfa3e5991a9075d98ac66330ab404dbc69ec8d/cffi-1.15.0-cp38-cp38-macosx_10_9_x86_64.whl (178 kB)
Collecting Pyphen>=0.9.1
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/89/e1/8e7313c8bf030ab5fc63f6a6b2f037b39fa2858fe1e93d3c06440a4b7614/pyphen-0.12.0-py3-none-any.whl (2.0 MB)
Collecting pycparser
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/62/d5/5f610ebe421e85889f2e55e33b7f9a6795bd982198517d912eb1c76e1a53/pycparser-2.21-py2.py3-none-any.whl (118 kB)
Collecting webencodings
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
Collecting brotli>=1.0.1
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/7f/e6/af68859d7a2f8c47d285e834ef781d4139f5a99dcdfe936fe7740e1b6978/Brotli-1.0.9-cp38-cp38-macosx_10_9_x86_64.whl (421 kB)
Collecting zopfli>=0.1.4
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/64/46/19b864c32eab0ec1a01404f2e4adebe03156c331feef5aa1f75736155400/zopfli-0.1.9-cp38-cp38-macosx_10_9_x86_64.whl (40 kB)
Collecting six>=1.9
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: webencodings, zopfli, tinycss2, six, pycparser, fonttools, brotli, Pyphen, pydyf, Pillow, html5lib, cssselect2, cffi, weasyprint
Successfully installed Pillow-9.0.0 Pyphen-0.12.0 brotli-1.0.9 cffi-1.15.0 cssselect2-0.4.1 fonttools-4.29.0 html5lib-1.1pycparser-2.21 pydyf-0.1.2 six-1.16.0 tinycss2-1.1.1 weasyprint-54.0 webencodings-0.5.1 zopfli-0.1.9
weasyprint --version
Traceback (most recent call last):
  File "/Users/kaizhao/var/virtualenvs/weasyprint/bin/weasyprint", line 5, in <module>
    from weasyprint.__main__ import main
  File "/Users/kaizhao/var/virtualenvs/weasyprint/lib/python3.8/site-packages/weasyprint/__init__.py", line 325, in <module>
    from .css import preprocess_stylesheet  # noqa isort:skip
  File "/Users/kaizhao/var/virtualenvs/weasyprint/lib/python3.8/site-packages/weasyprint/css/__init__.py", line 27, in <module>
    from . import computed_values, counters, media_queries
  File "/Users/kaizhao/var/virtualenvs/weasyprint/lib/python3.8/site-packages/weasyprint/css/computed_values.py", line 16, in <module>
    from ..text.ffi import ffi, pango, units_to_double
  File "/Users/kaizhao/var/virtualenvs/weasyprint/lib/python3.8/site-packages/weasyprint/text/ffi.py", line 403, in <module>
    gobject = _dlopen(
  File "/Users/kaizhao/var/virtualenvs/weasyprint/lib/python3.8/site-packages/weasyprint/text/ffi.py", line 390, in _dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "/Users/kaizhao/var/virtualenvs/weasyprint/lib/python3.8/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/Users/kaizhao/var/virtualenvs/weasyprint/lib/python3.8/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/Users/kaizhao/var/virtualenvs/weasyprint/lib/python3.8/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: cannot load library 'gobject-2.0-0': dlopen(gobject-2.0-0, 0x0002): tried: 'gobject-2.0-0' (no such file), '/usr/local/lib/gobject-2.0-0' (no such file), '/usr/lib/gobject-2.0-0' (no such file), '/Users/kaizhao/var/virtualenvs/gobject-2.0-0' (no such file), '/usr/local/lib/gobject-2.0-0' (no such file), '/usr/lib/gobject-2.0-0' (no such file).  Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'

@liZe
Copy link
Member

liZe commented Jan 31, 2022

This problem means that gobject is not found. The solution to solve that is different on Windows and on macOS.

@jancoow Do you use WeasyPrint 54.0?

@zhangkaizhao You have to use Homebrew’s Python to create your virtual environment, not another Python installed somewhere else. You’ll find more information in #1483.

@jancoow
Copy link
Author

jancoow commented Jan 31, 2022

This problem means that gobject is not found. The solution to solve that is different on Windows and on macOS.

@jancoow Do you use WeasyPrint 54.0?

@zhangkaizhao You have to use Homebrew’s Python to create your virtual environment, not another Python installed somewhere else. You’ll find more information in #1483.

I'm using the latest version, installed with pip3 install weasyprint

@liZe
Copy link
Member

liZe commented Jan 31, 2022

@jancoow OK. Did you install GTK in the default directory (C:\Program Files\GTK3-Runtime Win64\bin)? If you didn’t, you can try to set the installation folder in the WEASYPRINT_DLL_DIRECTORIES environment variable before launching WeasyPrint.

@jancoow
Copy link
Author

jancoow commented Jan 31, 2022

@jancoow OK. Did you install GTK in the default directory (C:\Program Files\GTK3-Runtime Win64\bin)? If you didn’t, you can try to set the installation folder in the WEASYPRINT_DLL_DIRECTORIES environment variable before launching WeasyPrint.

Yes, I did. I verified and I can see the gobject DLL in the bin directory.
I already tried setting that environment variable with no luck.

@liZe
Copy link
Member

liZe commented Jan 31, 2022

Yes, I did. I verified and I can see the gobject DLL in the bin directory.
I already tried setting that environment variable with no luck.

Hmmm, version 54.0 should then work out of the box with Python 3.8 or more recent… Do you use the 64-bit version of Python on a 64-bit version of Windows?

@jancoow
Copy link
Author

jancoow commented Jan 31, 2022

Yes, I did. I verified and I can see the gobject DLL in the bin directory.
I already tried setting that environment variable with no luck.

Hmmm, version 54.0 should then work out of the box with Python 3.8 or more recent… Do you use the 64-bit version of Python on a 64-bit version of Windows?

That is a good question! I did check if I have 64 bit Windows, but totally forget to check if I'm running a 64 bit version of python. I'll have to check tomorrow.

@liZe
Copy link
Member

liZe commented Feb 7, 2022

That is a good question! I did check if I have 64 bit Windows, but totally forget to check if I'm running a 64 bit version of python. I'll have to check tomorrow.

Did you find the time to check this?

@liZe
Copy link
Member

liZe commented Feb 13, 2022

Did you find the time to check this?

Don’t hesitate to reopen if needed!

@jakobowsky
Copy link

I am also facing the same problem. Running solution on the newest Mac book pro M1. Simply can't run it locally.
Did everything as here:
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#macos
On the previous Macbook with i9 it worked. Same on my Linux server.

@liZe
Copy link
Member

liZe commented Apr 12, 2022

I am also facing the same problem.

The problem is generally caused by not using Homebrew’s Python 3 to create the virtual environment. What does which python3 give after installing Homebrew’s Python?

@jakobowsky
Copy link

Just fixed it using:

sudo ln -s /opt/homebrew/opt/glib/lib/libgobject-2.0.0.dylib /usr/local/lib/gobject-2.0
sudo ln -s /opt/homebrew/opt/pango/lib/libpango-1.0.dylib /usr/local/lib/pango-1.0
sudo ln -s /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.dylib /usr/local/lib/harfbuzz
sudo ln -s /opt/homebrew/opt/fontconfig/lib/libfontconfig.1.dylib /usr/local/lib/fontconfig-1
sudo ln -s /opt/homebrew/opt/pango/lib/libpangoft2-1.0.dylib /usr/local/lib/pangoft2-1.0

Solution: #1448

@liZe
Copy link
Member

liZe commented Apr 13, 2022

Just fixed it using […]

It’s cool if it works for you.

Using Hombrew’s Python to create the virtual environment avoids the need to link libraries. It will also avoid the risk to break Homebrew, WeasyPrint or your whole system when you upgrade Homebrew packages. I really wouldn’t do this on my system, but it’s up to you 😄.

@samzong
Copy link

samzong commented May 8, 2022

It's working for me, thanks a lot

@minalike
Copy link

minalike commented May 11, 2022

Just fixed it using […]

It’s cool if it works for you.

Using Hombrew’s Python to create the virtual environment avoids the need to link libraries. It will also avoid the risk to break Homebrew, WeasyPrint or your whole system when you upgrade Homebrew packages. I really wouldn’t do this on my system, but it’s up to you 😄.

which python3 returns for me .venv/bin/python3 in my project directory. I made this virtual environment using poetry. (Possibly pyenv also plays a part?)

When my venv is not activated, which python3 returns /Users/mina/.pyenv/shims/python3

Can you explain your proposed method of "using Homebrew's Python" to create the venv?

EDIT: I experimented with installing python with homebrew and using homebrew's python3 to create a venv, and got the same error.

@liZe
Copy link
Member

liZe commented May 11, 2022

Can you explain your proposed method of "using Homebrew's Python" to create the venv?

What you have to do is to follow the installation guide:

  • Install python, pango and libffi with Homebrew, and check that which python3 returns the path to Hombrew’s Python. That’s necessary, because Hombrew’s Python is configured to automatically find libraries installed by Homebrew (including gobject), and these libraries are required by WeasyPrint.
  • Create your virtual environment with python3 -m venv venv. This virtual environment will be able to find Hombrew’s libraries, because it’s been created by Homebrew’s Python.
  • Activate your virtual environment with source venv/bin/activate.
  • Install WeasyPrint using pip install weasyprint.
  • Check that everything works fine with weasyprint --info.

Following these steps is not mandatory, there are endless solutions to make WeasyPrint work on macOS. But that’s the "official" way we can help users to follow, because we know that it’s safe and reliable.

@puluo2void
Copy link

Just fixed it using:

sudo ln -s /opt/homebrew/opt/glib/lib/libgobject-2.0.0.dylib /usr/local/lib/gobject-2.0 sudo ln -s /opt/homebrew/opt/pango/lib/libpango-1.0.dylib /usr/local/lib/pango-1.0 sudo ln -s /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.dylib /usr/local/lib/harfbuzz sudo ln -s /opt/homebrew/opt/fontconfig/lib/libfontconfig.1.dylib /usr/local/lib/fontconfig-1 sudo ln -s /opt/homebrew/opt/pango/lib/libpangoft2-1.0.dylib /usr/local/lib/pangoft2-1.0

Solution: #1448

This work for me on Mac M1 Pro.
Thanks

@rahul-trip
Copy link

Hi

I am facing this on ubuntu 20.0

@zh-tan
Copy link

zh-tan commented Apr 1, 2024

Just fixed it using:

sudo ln -s /opt/homebrew/opt/glib/lib/libgobject-2.0.0.dylib /usr/local/lib/gobject-2.0 sudo ln -s /opt/homebrew/opt/pango/lib/libpango-1.0.dylib /usr/local/lib/pango-1.0 sudo ln -s /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.dylib /usr/local/lib/harfbuzz sudo ln -s /opt/homebrew/opt/fontconfig/lib/libfontconfig.1.dylib /usr/local/lib/fontconfig-1 sudo ln -s /opt/homebrew/opt/pango/lib/libpangoft2-1.0.dylib /usr/local/lib/pangoft2-1.0

Solution: #1448

this works on Mac M3. Thanks

@rayud
Copy link

rayud commented Jun 11, 2024

I'm still facing issues in windows 11

@liZe
Copy link
Member

liZe commented Jun 11, 2024

I'm still facing issues in windows 11

Please follow the install steps. If it doesn’t work, please open a new issue.

@Kozea Kozea locked as resolved and limited conversation to collaborators Jun 11, 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

10 participants