attributeError:模块' collections'没有属性'迭代'

发布于 2025-02-01 11:16:53 字数 1127 浏览 5 评论 0原文

我正在使用“ pdftables”库从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获取库

I am using the "pdftables" library to extract tables from a pdf.

This is my code:

import pdftables

pg = pdftables.get_pdf_page(open("filename.pdf","rb"),253)

print(pg)

table = pdftables.page_to_tables(pg)

print(table)

I am getting this error and I am not sure what's causing it.

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'

The version of python I am using is python 3.10.4

I used pip install pdftables.six to get the library

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眉黛浅 2025-02-08 11:16:53

如果您不想更改源代码,则有一种更简单的方法。导入后,只需在脚本中使用它即可。

import collections
collections.Iterable = collections.abc.Iterable

If you don't want to change the source code, there is an easier way. Just use this in your script after importing.

import collections
collections.Iterable = collections.abc.Iterable
孤凫 2025-02-08 11:16:53

正如错误所说,属性无效。使用collection.iterable时,它找不到itoble属性。这可能有不同的原因,但是在这种情况下,在Github上查看了包装文件后,我注意到您缺少ABC关键字。我没有尝试过此解决方案,但是我95%肯定使用collections.abc.iterable会做这件事。

As the Error says, the attribute isn't valid. When using collection.Iterable then it not finds the Iterable attribute. This can have different reasons but in this case, after looking on the package files on Github, i noticed that you are missing the abc keyword. I not tried this solution, but I'm 95% sure that using collections.abc.Iterable will do the thing.

import collections 
from _collections_abc import Iterable 
collection.Iterable = Iterable

这应该起作用

import collections 
from _collections_abc import Iterable 
collection.Iterable = Iterable

This should work ????

街道布景 2025-02-08 11:16:53

一个适用于Python3.10的简单修复程序:

在目录下
/usr/lib/python3.10/collections/collections/__ init__。py

note :路径可能会根据

添加以下代码而改变:

from _collections_abc from _collections_abc导入iToct /代码>

A simple fix that works for python3.10:

Under directory
/usr/lib/python3.10/collections/__ init__.py

Note: The path might change depending

Add this line of code:

from _collections_abc import Iterable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文