我正在使用“pdftable”库从pdf中提取表格。
这是我的密码:
import pdftables
pg = pdftables.get_pdf_page(open("filename.pdf","rb"),253)
print(pg)
table = pdftables.page_to_tables(pg)
print(table)我得到了这个错误,我不知道是什么原因造成的。
Traceback (most recent call last):
File "c:\Users\gayak\OneDrive\Documents\PDF to Database\PDF_to_Tables_3.py", line 9, in <module>
table = pdftables.page_to_tables(pg)
File "C:\Users\gayak\AppData\Local\Programs\Python\Python310\lib\site-packages\pdftables\pdftables.py", line 485, in page_to_tables
box_list = LeafList().populate(page, flt).purge_empty_text()
File "C:\Users\gayak\AppData\Local\Programs\Python\Python310\lib\site-packages\pdftables\tree.py", line 98, in populate
for obj in children(pdfpage):
File "C:\Users\gayak\AppData\Local\Programs\Python\Python310\lib\site-packages\pdftables\tree.py", line 75, in children
if isinstance(obj, collections.Iterable):
AttributeError: module 'collections' has no attribute 'Iterable'我使用的python版本是python 3.10.4
我用pip install pdftables.six得到了图书馆
发布于 2022-07-20 07:00:05
如果您不想更改源代码,有一个更简单的方法。导入后,只需在脚本中使用这个即可。
import collections
collections.Iterable = collections.abc.Iterable发布于 2022-05-25 08:33:14
正如错误所述,该属性无效。当使用collection.Iterable时,它不会找到Iterable属性。这可能有不同的原因,但在本例中,在查看Github上的包文件后,我注意到您缺少abc关键字。我没有尝试过这个解决方案,但我95%肯定使用collections.abc.Iterable就能做到这一点。
发布于 2022-11-23 21:52:36
一个适用于python3.10的简单修复:
目录下/usr/lib/python3.10/collections/init.py
注意事项:路径可能会根据不同而改变
添加这一行代码:
from _collections_abc import Iterable
https://stackoverflow.com/questions/72371859
复制相似问题