python - Mac Poppler + pdf2image 路径错误
问题描述
问题: 我一直在尝试使用 Python 库 pdf2image,我知道它需要预先安装 poppler。Poppler 已安装(通过自制软件)并通过 pip 安装软件包。
但是,在运行时,convert_to_path(my_pdf)
我得到以下信息:
Traceback (most recent call last):
File "<ipython-input-9-ba107659b495>", line 1, in <module>
test_image = convert_from_path(testfile,
File "/Users/<myuser>/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pdf2image/pdf2image.py", line 97, in convert_from_path
page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)["Pages"]
File "/Users/<myuser>/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pdf2image/pdf2image.py", line 467, in pdfinfo_from_path
raise PDFInfoNotInstalledError(
PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
我的系统:Mac,OC 10.15.7 Python(通过 Homebrew)版本 3.8.0
which python
/Users/<myuser>/.pyenv/shims/python
which pip
/Users/<myuser>/.pyenv/shims/pip
到目前为止我已经尝试过:Poppler 是通过自制软件
安装的brew install poppler
(pip3 install pdf2image
brew cleanup
尝试使用以下命令强制 convert_to_path 中的 poppler 路径,
pop_path = "/usr/local/Cellar/poppler/21.03.0_1"
convert_to_path(my_pdf_file,poppler_path = pop_path)
但仍然得到同样的错误。
在网上看了一下,发现很多人有类似但不完全相同的问题。我觉得我一定做错了什么,所以任何指导都会很棒。
解决方案
部分解决方案?
在手动输入 pop_path 文件路径时,我忘记将 /bin 附加到路径中,
pop_path = "/usr/local/Cellar/poppler/21.03.0_1/bin"
该代码现在有效。虽然我的自尊需要一段时间才能恢复...
我觉得我可能仍然坐在一个糟糕的配置问题上?关于类似问题的许多帖子似乎暗示自制软件安装的popper不应该有这个问题。可能是因为我也在使用 pyenv 吗?
推荐阅读
- python - 无法使用 Selenium 在 youtube 中向下滚动(我的代码可以运行某些网站,但不能使用 Youtube)
- python - sqlalchemy 将两个表连接在一起
- kotlin - 通用约束作为类型列表?还是编译时鸭子类型?
- python - 我想在 django-rest-framework 中创建一个评论功能
- netsuite - 为什么定价搜索不返回有价格的项目的结果?
- java - 使用 Room 加载复杂的数据结构(带有关系和继承)
- multi-tenant - EF Core 迁移 - 多个数据库
- c# - 将时间执行计算为单独的类,其中函数是可变的
- c - For循环没有做预期的事情
- javascript - 添加延迟(同步)与除 IE 之外的现代浏览器一起使用