我正在尝试使用 Python 中的 unstructed、unstructed[pdf] 库对 .pdf 文件进行分区,但我遇到了一个似乎无法解决的错误。 pdf 文件包含文本、表格、图像...
以下是我正在做的事情的简要概述:
from unstructured.partition.pdf import partition_pdf
path = '/content/'
file_name = 'ABCABC.pdf'
raw_pdf_elements = partition_pdf(
filename=path + file_name,
extract_images_in_pdf=True,
infer_table_structure=True,
chunking_strategy="by_title",
max_characters=4000,
new_after_n_chars=3800,
combine_text_under_n_chars=2000,
image_output_dir_path=path
)
错误消息: 当我运行代码时,出现以下错误:
NameError: name 'sort_page_elements' is not defined
环境:
问题:
什么可能导致此 NameError,以及如何解决它?任何帮助将不胜感激!
更新
我尝试过解决方案@Oluwafemi Sule,但它不起作用,我的环境同时有 numpy 和 opencv-python
您有一个
NameError
,因为 partition_pdf
调用 document_to_element_list 函数,并且它调用 sort_page_elements
sort_page_elements
仅当 numpy 和 cv2 库可用时才会导入到模块中。