37
This was solved for me by installing the following dependencies on Ubuntu:
sudo apt-get install libpango1.0-0
sudo apt-get install libcairo2
sudo apt-get install libpq-dev
Check out the dependencies at the link:
16
I also had the same issue on a fresh installation of weasyprint
on OSX EL CAPITAN.
This is how I solved it.
Firstly, cairo
was not found by when installed via pip, so I tried installing it via homebrew using the following command
brew install cairo pango gdk-pixbuf libxml2 libxslt libffi
Once this is done, I tried to find out the path of cairo
installation. For my case, the location was /usr/local/homebrew/Cellar/cairo/1.14.6_1/lib/
I just exported this to my DYLD library path
export DYLD_LIBRARY_PATH=/usr/local/homebrew/Cellar/cairo/1.14.6_1/lib/
Then I uninstalled and installed weasyprint
again
pip uninstall weasyprint
pip install weasyprint
Post that, I tried to run weasyprint
, but got a new error
Traceback (most recent call last):
File "/Users/anurag/VirtualEnvs/test/bin/weasyprint", line 11, in <module>
load_entry_point('WeasyPrint==0.31', 'console_scripts', 'weasyprint')()
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/pkg_resources/__init__.py", line 565, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2598, in load_entry_point
return ep.load()
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2258, in load
return self.resolve()
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2264, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/weasyprint/__init__.py", line 338, in <module>
from .css import PARSER, preprocess_stylesheet # noqa
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/weasyprint/css/__init__.py", line 30, in <module>
from . import computed_values
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/weasyprint/css/computed_values.py", line 18, in <module>
from .. import text
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/weasyprint/text.py", line 216, in <module>
'libgobject-2.0.dylib')
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/weasyprint/text.py", line 212, in dlopen
return ffi.dlopen(names[0]) # pragma: no cover
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/cffi/api.py", line 139, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/cffi/api.py", line 770, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "/Users/anurag/VirtualEnvs/test/lib/python2.7/site-packages/cffi/api.py", line 759, in _load_backend_lib
return backend.load_library(name, flags)
OSError: cannot load library gobject-2.0: dlopen(gobject-2.0, 2): image not found
I tried to find out the location of object
library. Found it in /opt/local/lib
and set the fallback library path
export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib
After that, I tried running weasyprint
again, and it worked
(test)anurag-mac:~ anurag$ weasyprint --version
WeasyPrint version 0.31
I hope someone else also finds it useful.
UPDATE-1
Although the above method worked, MySQL python started giving errors because of this and culprit
was defining a fallback library path. So I removed this line
export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib
which gave me the gobject
error again, then I tried finding the location of its installation and appended to the DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=/usr/local/homebrew/Cellar/cairo/1.14.6_1/lib/:/usr/local/homebrew/Cellar/glib/2.48.2/lib/
After doing that, I got a similar error for pango
. After correcting all the errors, this is the final library path which worked
export DYLD_LIBRARY_PATH=/usr/local/homebrew/Cellar/cairo/1.14.6_1/lib/:/usr/local/homebrew/Cellar/glib/2.48.2/lib/:/usr/local/homebrew/Cellar/pango/1.40.3/lib/
- [Django]-Django multi-select widget?
- [Django]-Managing static files for multiple apps in Django
- [Django]-How to allow users to change their own passwords in Django?
3
I had the same error with boxes.py on macOS Mojave. My solution was to install cairocffi
with pip3
and cairo
with brew
. The two commands fail on their own, but together they work for boxes.py
:
pip3 install cairocffi
brew install cairo
- [Django]-Convert string array to array in javascript
- [Django]-Python MySQLDB: Get the result of fetchall in a list
- [Django]-Setting the selected value on a Django forms.ChoiceField
1
If you are getting this error when using weasyprint, then you may have forgotten to install Pango, GdkPixbuf, and cairo dependencies of weasyprint which cannot be installed using pip/pip3
For Debain/Ubuntu
sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
For other platforms refer the below link
- [Django]-Custom django admin templates not working
- [Django]-Control the size TextArea widget look in django admin
- [Django]-Github issues api 401, why? (django)
0
I solve this problem by following this link:
https://github.com/Kozea/WeasyPrint/issues/79
- [Django]-Paginator for inline models in django admin
- [Django]-Override existing Django Template Tags
- [Django]-Django: implementing JOIN using Django ORM?
-2
sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
http://weasyprint.readthedocs.io/en/latest/install.html#linux
- [Django]-Replace textarea with rich text editor in Django Admin?
- [Django]-When to use or not use iterator() in the django ORM
- [Django]-How to use the request in a ModelForm in Django