9

我在OSError: dlopen() failed to load a library: cairo / cairo-2新安装后尝试执行 Django。使用 Windows。

根据完整的跟踪,我正在使用 Wea​​syprint,似乎与那个有关:

Unhandled exception in thread started by <function wrapper at 0x03F605B0>
Traceback (most recent call last):
  File "C:\my-venv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\my-venv\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "C:\my-venv\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "C:\my-venv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\my-venv\lib\site-packages\django\__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\my-venv\lib\site-packages\django\apps\registry.py", line 115, in populate
    app_config.ready()
  File "C:\my-venv\lib\site-packages\debug_toolbar\apps.py", line 15, in ready
    dt_settings.patch_all()
  File "C:\my-venv\lib\site-packages\debug_toolbar\settings.py", line 243, in patch_all
    patch_root_urlconf()
  File "C:\my-venv\lib\site-packages\debug_toolbar\settings.py", line 231, in patch_root_urlconf
    reverse('djdt:render_panel')
  File "C:\my-venv\lib\site-packages\django\core\urlresolvers.py", line 568, in reverse
    app_list = resolver.app_dict[ns]
  File "C:\my-venv\lib\site-packages\django\core\urlresolvers.py", line 360, in app_dict
    self._populate()
  File "C:\my-venv\lib\site-packages\django\core\urlresolvers.py", line 293, in _populate
    for pattern in reversed(self.url_patterns):
  File "C:\my-venv\lib\site-packages\django\utils\functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\my-venv\lib\site-packages\django\core\urlresolvers.py", line 417, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\my-venv\lib\site-packages\django\utils\functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\my-venv\lib\site-packages\django\core\urlresolvers.py", line 410, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\my-project\project\urls.py", line 9, in <module>
    from utils.views import site_info, nav_autocomplete
  File "C:\my-project\utils\views.py", line 24, in <module>
    import weasyprint
  File "C:\my-venv\lib\site-packages\weasyprint\__init__.py", line 338, in <module>
    from .css import PARSER, preprocess_stylesheet  # noqa
  File "C:\my-venv\lib\site-packages\weasyprint\css\__init__.py", line 30, in <module>
    from . import computed_values
  File "C:\my-venv\lib\site-packages\weasyprint\css\computed_values.py", line 18, in <module>
    from .. import text
  File "C:\my-venv\lib\site-packages\weasyprint\text.py", line 18, in <module>
    import cairocffi as cairo
  File "C:\my-venv\lib\site-packages\cairocffi\__init__.py", line 46, in <module>
    cairo = dlopen(ffi, 'cairo', 'cairo-2')
  File "C:\my-venv\lib\site-packages\cairocffi\__init__.py", line 43, in dlopen
    raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
OSError: dlopen() failed to load a library: cairo / cairo-2
4

3 回答 3

4

请参阅http://win32builder.gnome.org/http://gtk-win.sourceforge.net/home/以获取要安装的 GTK+ 包的列表。其中包括所需的 cairo/cairo-2 库。

  • 将文件夹的内容提取bin\到例如C:\Program Files (x86)\GTK2-bundle\(任何目录都可以)
  • 将上述目录添加到您的 PATH 环境变量中
  • 重新启动您的开发环境(在我的情况下为 PyCharm)
于 2016-07-24T20:16:40.670 回答
1

我收到以下错误消息:OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2,在 Windows 10 上。

包含上述库的 GTK+ 库可以从 https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer获取和安装,如https://weasyprint.readthedocs.io/en中所述/latest/install.html#gtk64installer

请注意,您的开发环境需要重新启动才能读取PATH.

于 2020-12-29T10:40:34.303 回答
0

我在 Windows X64/Python37 上遇到了同样的问题,但我用下面的链接修复了:

请按照以下步骤操作:https ://weasyprint.readthedocs.io/en/stable/install.html#windows,(我使用 MSYS Installer 安装了 gtk 并将 C:\msys64\mingw32\bin 添加到 PATH 变量中,之后我发生了同样的错误,我删除了 cairocffi python 库并重新安装它)

于 2019-03-07T06:42:17.633 回答