gpt4 book ai didi

python-3.x - 从 .pdftypes 导入 PDFObjectNotFound ImportError : cannot import name 'PDFObjectNotFound'

转载 作者:行者123 更新时间:2023-12-05 02:13:40 25 4
gpt4 key购买 nike

我正在尝试将 PDF 转换为文本。但是我在 PDFPage 类中遇到问题。我已经搜索过了。但我什么也没得到,它给了我以下错误。我还为 python 3.5 安装了 pdfminer.six 但我仍然没有得到任何解决方案。请帮忙。

代码:

from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
import os
import sys, getopt

#converts pdf, returns its text content as a string


def extract_text_from_pdf(pdf_path):
with open(pdf_path, 'rb') as fh:
for page in PDFPage.get_pages(fh,
caching=True,
check_extractable=True):
resource_manager = PDFResourceManager()
fake_file_handle = io.StringIO()
converter = TextConverter(resource_manager, fake_file_handle, codec='utf-8', laparams=LAParams())
page_interpreter = PDFPageInterpreter(resource_manager, converter)
page_interpreter.process_page(page)

text = fake_file_handle.getvalue()
yield text

# close open handles
converter.close()
fake_file_handle.close()

错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/system/anaconda3/lib/python3.6/site-packages/pdfminer/pdfpage.py", line 5, in <module>
from .pdftypes import PDFObjectNotFound
ImportError: cannot import name 'PDFObjectNotFound'

最佳答案

卸载pdfminer3k(如果你安装了它)

$ pip uninstall pdfminer3k

并使用以下命令安装 pdfminer.six

$ python -m pip install pdfminer.six

关于python-3.x - 从 .pdftypes 导入 PDFObjectNotFound ImportError : cannot import name 'PDFObjectNotFound' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54778931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com