运行Django服务器时,我看到了这个问题!!
OSError: no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x
cannot load library 'libcairo-2.dll': error 0x7e
答案 0 :(得分:6)
对我来说,安装GTK +无效。 我使用UniConverter2.0解决了这个问题。 我的环境是
C:\Program Files\UniConvertor-2.0rc4\dlls
)答案 1 :(得分:2)
在此处查看解决方案:
https://www.programmersought.com/article/47674569357/
如果安装后没有添加,则需要添加路径:
C:\Program Files\GTK3-Runtime Win64\bin
我已经用这种方法解决过很多次了。
答案 2 :(得分:0)
WeasyPrint需要Pango,cairo和GDK-PixBuf库。它们是GTK +(以前称为GIMP Toolkit)的一部分,必须单独安装。
安装GTK+ libraries后,请执行:
python -m weasyprint http://weasyprint.org weasyprint.pdf
答案 3 :(得分:0)
从Python 3.8开始,需要单独添加dll。 添加了GTK +,MSYS2,Visual Studio C编译器和Uniconverter。但是,似乎没有任何效果。 最终,在放置了用于调用add_dll_directory的脚本之后,它才能正常工作。
import os
def set_dll_search_path():
# Python 3.8 no longer searches for DLLs in PATH, so we have to add
# everything in PATH manually. Note that unlike PATH add_dll_directory
# has no defined order, so if there are two cairo DLLs in PATH we
# might get a random one.
if os.name != "nt" or not hasattr(os, "add_dll_directory"):
return
for p in os.environ.get("PATH", "").split(os.pathsep):
try:
os.add_dll_directory(p)
except OSError:
pass
set_dll_search_path()
答案 4 :(得分:0)
可能有点晚了,但我刚刚遇到了同样的问题,并且:
从这里开始:https://weasyprint.readthedocs.io/en/stable/install.html#windows
。在哪里可以找到包含所需 DLL 的 GTK 包的链接。
就我而言,我有一个 64 位 Python,所以我使用:“Download and run the latest gtk3-runtime-x.x.x-x-x-x-ts-win64.exe
”
我没有改变安装目录
安装完成后。我将路径添加到我的变量路径中。
我重新启动了终端,确保可以使用以下命令找到 DLL:WHERE libcairo-2.dll
。这返回了C:\Program Files\GTK3-Runtime Win64\bin\libcairo-2.dll
然后我运行 python -m weasyprint http://weasyprint.org weasyprint.pdf
并收到了一些警告,但它们只是警告:)