我使用的是 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
但是仍然有错误。
您可以使用以下方式安装 CairoSVG 2.7.1:
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++ 编译器。