图像处理¶
一些[内置插件]依赖于外部库来获得高效的图像 处理,最值得注意的是生成[社交卡]的[社交]插件,以及 用于应用[图像优化]的[optimization]插件。本指南解释了如何 在不同的环境中安装这些库。
依赖关系¶
用于图像处理的库是完全可选的,只需要 如果你想使用[社交]插件或[优化]插件,请安装。这个 库列在“图像”附加项下:
这将安装以下软件包的兼容版本:
开罗图形¶
Cairo Graphics是[Phillow]的图形库和依赖项 MkDocs的材料用于生成[社交卡]和执行 [图像优化]。请参阅以下部分,了解如何安装 Cairo Graphics及其对您系统的依赖性:
Make sure Homebrew is installed, which is a modern package manager for macOS. Next, use the following command to install all necessary dependencies:
The easiest way to get up and running with the Cairo Graphics library is by installing it via MSYS2, which is a software distribution and building platform for Windows. Run the following command inside of a MSYS2 shell:
MSYS2 provides the Cairo Graphics library in several different environments. The above command uses the UCRT64 environment, as recommended by the MSYS2 developers.
There are several package managers for Linux with varying availability per distribution. The installation guide explains how to install the Cairo Graphics library for your distribution:
以下环境附带了预装的[Caroo Graphics]版本:
- No installation needed in Docker image
- No installation needed in GitHub Actions (Ubuntu)
pngquant¶
pngquant是一个优秀的有损PNG压缩库 [内置优化插件]的依赖关系。请参阅以下部分 解释了如何安装pngquant系统:
Make sure Homebrew is installed, which is a modern package manager for macOS. Next, use the following command to install all necessary dependencies:
以下环境预装了pngquant版本:
- No installation needed in Docker image
故障排除¶
找不到开罗图书馆¶
按照上面的安装指南进行操作后,可能会出现以下情况: 以下错误:
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'
这意味着安装了[cairosvg
][PyPi-cairosvg]包,但 基础[cairocffi
][PyPi-cairocffi]依赖项无法[找到][cffi dopen] 已安装的库。根据操作系统,库查找 过程不同:
Tip
在继续之前,请记住完全重新启动任何打开的终端窗口,以及 它们的父主机像IDE一样重新加载任何环境变量,这 在安装过程中被更改。这可能是快速解决方案。
在macOS上,库查找会检查dyld中定义的路径内部。 此外,每个库“名称”都在[三个变体][查找库macOS]中检查 使用libname.dylib
、name.dylib
和name.framework/name
格式。
Homebrew应将所有需要的变量设置为指向已安装的 库目录,但如果没有发生这种情况,您可以使用调试脚本 下面查看查找的路径。
一个[已知的解决方法][cffi问题]是直接添加Homebrew库路径 在运行MkDocs之前:
查看[cairo lookup macos.py的源代码]
在Windows上,库查找检查中定义的路径内部 环境变量“PATH”。此外,还会检查每个库的“名称” 在[两种变体][查找库窗口]中,使用“name”和“name.dll”格式。
UCRT64环境的默认二进制和共享库路径 MSYS2是使用上述命令安装软件包的:
使用下面的调试脚本检查是否包含路径。如果不是,那么:
- 按++窗口+r++。
- 运行“SystemPropertiesAdvanced”小程序。
- 选择底部的“环境变量”。
- 将上述目录的整个路径添加到“path”变量中。
- 在所有打开的窗口上单击“确定”以应用更改。
- 完全重新启动任何打开的终端窗口及其父主机,如IDE。
查看[cairo查找窗口.py]的源代码
在Linux上,库查找可以[差异很大][查找库Linux] 取决于已安装的分发。适用于经过测试的Ubuntu和Manjaro 系统Python运行shell命令来检查哪些库在 在[gcc][ubuntu-gcc]/
cc编译器中的[
ldconfig][ubuntu ldconfig],以及 在ld中。
您可以使用绝对值扩展“LD_LIBRARY_PATH”环境变量 包含“libcairo.so”等的库目录的路径。直接运行此命令 在MkDocs之前:
您还可以修改/etc/ld.so.conf
文件。
下面的Python脚本显示了正在运行哪个函数来查找已安装 图书馆。您可以查看源代码以了解具体命令是什么 在库查找期间在您的系统上执行。
查看[cairo-lookup linux.py的源代码]