将 Mac 更新至 El Capitan 后运行 WeasyPrint

将 Mac 更新至 El Capitan 后运行 WeasyPrint

我最近将我的 Mac 上的操作系统更新为 El Capitan,从那时起,在尝试运行 WeasyPrint 时遇到了问题。我已经更新了 macports,卸载并重新安装了所有 macport 依赖项。我还通过 pip 卸载并重新安装了 WeasyPrint,没有任何问题,但它仍然无法运行。我的 ~/.profile 中还有 export DYLD_FALLBACK_LIBRARY_PATH="/opt/local/lib",这有助于解决导入错误并允许 WeasyPrint 在安装 El Capitan 之前运行。当我在终端中输入 weasyprint --help 时,我收到以下输出/错误:

File "main.py", line 14, in <module>
    import nextline_webapp.quotes                   # pylint: disable=unused-import
  File "/Users/joshsacks/NextLine/nextline_webapp/quotes.py", line 8, in <module>
    from flask_weasyprint import HTML, render_pdf
  File "/Library/Python/2.7/site-packages/flask_weasyprint/__init__.py", line 13, in <module>
    import weasyprint
  File "/Library/Python/2.7/site-packages/weasyprint/__init__.py", line 336, in <module>
    from .css import PARSER, preprocess_stylesheet
  File "/Library/Python/2.7/site-packages/weasyprint/css/__init__.py", line 30, in <module>
    from . import computed_values
  File "/Library/Python/2.7/site-packages/weasyprint/css/computed_values.py", line 18, in <module>
    from .. import text
  File "/Library/Python/2.7/site-packages/weasyprint/text.py", line 18, in <module>
    import cairocffi as cairo
  File "/Library/Python/2.7/site-packages/cairocffi/__init__.py", line 46, in <module>
    cairo = dlopen(ffi, 'cairo', 'cairo-2')
  File "/Library/Python/2.7/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

这看起来像是路径问题,但我已经尝试了所有能想到的方法。有什么建议吗?

答案1

我遇到了类似的问题,对我来说它有帮助

  1. 在 .zshrc / .bashrc 中设置我的语言环境
  2. 确保拥有所有依赖项

设置区域设置:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

确保依赖项已安装:

brew install python cairo pango gdk-pixbuf libxml2 libxslt libffi

相关内容