WeasyPrint: Installation problem on macOS M1 chip
I have Python already on macOS version 11.6 using Pyenv.
$ python --version
Python 3.9.6
I followed the doc for installation.
pip install weasyprint
brew install pango libffi
I get the following error.
weasyprint --info
Traceback (most recent call last):
File "/Users/shinichiokada/.pyenv/versions/3.9.6/bin/weasyprint", line 5, in <module>
from weasyprint.__main__ import main
File "/Users/shinichiokada/.pyenv/versions/3.9.6/lib/python3.9/site-packages/weasyprint/__init__.py", line 322, in <module>
from .css import preprocess_stylesheet # noqa isort:skip
File "/Users/shinichiokada/.pyenv/versions/3.9.6/lib/python3.9/site-packages/weasyprint/css/__init__.py", line 27, in <module>
from . import computed_values, counters, media_queries
File "/Users/shinichiokada/.pyenv/versions/3.9.6/lib/python3.9/site-packages/weasyprint/css/computed_values.py", line 16, in <module>
from ..text.ffi import ffi, pango, units_to_double
File "/Users/shinichiokada/.pyenv/versions/3.9.6/lib/python3.9/site-packages/weasyprint/text/ffi.py", line 380, in <module>
gobject = _dlopen(
File "/Users/shinichiokada/.pyenv/versions/3.9.6/lib/python3.9/site-packages/weasyprint/text/ffi.py", line 377, in _dlopen
return ffi.dlopen(names[0]) # pragma: no cover
File "/Users/shinichiokada/.pyenv/versions/3.9.6/lib/python3.9/site-packages/cffi/api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "/Users/shinichiokada/.pyenv/versions/3.9.6/lib/python3.9/site-packages/cffi/api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "/Users/shinichiokada/.pyenv/versions/3.9.6/lib/python3.9/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, 2): image not found. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'
I installed gtk3.
brew install gtk+3
But it doesn’t solve the problem.
How can I solve the problem?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (7 by maintainers)
I found the solution here
You need to run the following:
Now it returns some info:
@liZe Do you have any references or more info on how to do that in a good way? I normally use pyenv.
For anyone else encountering this issue:
By default Python looks in
/usr/local/libfor libraries with ctypes: https://github.com/python/cpython/blob/v3.10.0/Lib/ctypes/macholib/dyld.py#L22 - however Homebrew versions of Python patch this to look in/opt/homebrew/lib: https://github.com/Homebrew/homebrew-core/blob/af990d0d5e3d70bd52b1e9acf1b0636e74851cac/Formula/python@3.9.rb#L187 - which is something Python versions from pyenv are lacking.Annoyingly the source for dyld.py suggests that setting
DYLD_FALLBACK_LIBRARY_PATHas an environment variable could be a workaround for this. Sadly if you’re calling Python with#!/usr/bin/envfrom a script (eg. Django./manage.py), macOS System Integrity Protection decides to remove such environment variables for security.Ideally a patched Python is the best route for this, however failing that - symbolic links should work.
Hello!
Linking Hombrew libraries outside Homebrew is not a good solution in my opinion. You should use Homebrew’s Python instead of using your system’s version of Python (see https://github.com/Kozea/WeasyPrint/issues/1448#issuecomment-925559421).