在 Windows 上导入 `cairosvg` 时出错 - Python

问题描述 投票:0回答:1

我使用的是 Windows (Windows 11)

我使用

cairosvg
安装了
pip
:

pip install cairosvg

但是当我导入它时出现此错误:

OSError: no library called "cairo-2" was found
no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.so.2'
cannot load library 'libcairo.2.dylib': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.2.dylib'
cannot load library 'libcairo-2.dll': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo-2.dll'

我尝试了很多修复,包括安装 GTK+ Runtime:

OSError: no library called "cairo-2" was found
no library called "cairo" was found
cannot load library 'C:\GTK+ Runtime\bin\libcairo-2.dll': error 0xc1
cannot load library 'libcairo.so.2': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.so.2'
cannot load library 'libcairo.2.dylib': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libcairo.2.dylib'
cannot load library 'C:\GTK+ Runtime\bin\libcairo-2.dll': error 0xc1

但是仍然有错误。

希望你能帮助我。

python cairo
1个回答
0
投票

可以用pip安装:

python -m pip install CairoSVG

确保您使用受支持的 Python 版本。根据文档

当前版本的 CairoSVG 至少需要 Python 3.6,它不适用于 Python 2.x。旧版本的 CairoSVG (1.x) 可与 Python 2.x 配合使用,但不再受支持。 CairoSVG 及其依赖项在安装过程中可能需要其他工具:编译器、Python 标头、Cairo 和 FFI 标头。根据您使用的操作系统,这些工具有不同的名称。

请注意,在 Windows 上,您必须安装 Cairo(例如 GTK)和 Python 的 Visual C++ 编译器

© www.soinside.com 2019 - 2024. All rights reserved.