AttributeError: module 'collections' has no attribute 'Iterable'

9.1k views Asked by At

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

4

There are 4 answers

0
Toastlover On

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.

1
Michael Crown On
import collections 
from _collections_abc import Iterable 
collection.Iterable = Iterable

This should work

0
Namwanza Ronald On

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

0
Sawradip Saha On

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