poppler_path 是用于 Python 库如 pdf2image 进行 PDF 转换时
poppler_path 是用于 Python 库如 pdf2image 进行 PDF 转换时指定 Poppler 可执行文件路径的参数。为了让程序正常工作,需要先安装 Poppler,并配置环境变量或在代码中设置 poppler_path。
以下是 Poppler 的安装与环境变量配置方法,按操作系统分别说明:
💻 Windows 系统
1. 下载 Poppler
* 访问 [Poppler for Windows](http://blog.alivate.com.au/popplerwindows/)
* 下载 popplerxx_xx_xx.zip(推荐 "latest binary")
* 解压缩到一个文件夹,例如:C:\poppler
2. 配置环境变量
1. 复制解压后的路径,比如:
C:\poppler\Library\bin
2. 打开【控制面板】→【系统】→【高级系统设置】→【环境变量】
3. 找到系统变量中的 Path,点击【编辑】,添加上述路径
4. 确认保存后,打开命令行输入:
where pdfinfo
如果返回了 pdfinfo.exe 的路径,说明配置成功。
3. Python 中使用(如果不配置环境变量)
python
from pdf2image import convert_from_path
images = convert_from_path("example.pdf", poppler_path=r"C:\poppler\Library\bin")
🐧 Linux 系统(如 Ubuntu)
Poppler 通常可以直接通过包管理器安装:
bash
sudo apt update
sudo apt install popplerutils
安装后,Poppler 的工具如 pdftoppm 和 pdfinfo 默认已在系统路径中,无需设置 poppler_path。
🍎 macOS 系统
通过 Homebrew 安装:
bash
brew install poppler
同样,Poppler 工具会自动加入 PATH,Python 中无需设置 poppler_path。