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
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
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
This should work 🙂
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
Related
I have been encountering this error within my chatterbot script when attempting to use the train function from a file list:
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\pythonProject\project\main.py", line 60, in <module>
trainer.train(file_list)
File "C:\Users\user\pythonProject\lib\site-packages\chatterbot\trainers.py", line 136, in train
data_file_paths.extend(list_corpus_files(corpus_path))
File "C:\Users\user\pythonProject\lib\site-packages\chatterbot\corpus.py", line 46, in list_corpus_files
corpus_path = get_file_path(dotted_path, extension=CORPUS_EXTENSION)
File "C:\Users\user\pythonProject\lib\site-packages\chatterbot\corpus.py", line 20, in get_file_path
parts = dotted_path.split('.')
AttributeError: 'list' object has no attribute 'split'
Here is the code for reference:
import os
import re
import yaml
import transformers
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from Cognify.cleaner import clean_corpus
I am using .yml files found in the chatterbot git as a reference piece in order to ensure it functions, but I cannot seem to get it to read the files. The trainer I am using is based off of the ChatterBotCorpusTrainer, as I have read that it is meant for reading .yml files. Additionally, it calls on the cleaner script, which is an external script that cleans and preprocesses data from the user so the bot can process the data after (although, I am not sure it is necessary).
Here is where I actually call the trainer:
chatbot = ChatBot("Cognify")
trainer = ChatterBotCorpusTrainer(chatbot)
file_list = [
"C:/Users/user/PycharmProjects/pythonProject/directory/ai.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/botprofile.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/computers.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/conversations.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/emotion.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/food.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/gossip.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/greetings.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/health.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/history.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/humor.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/literature.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/money.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/movies.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/politics.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/psychology.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/science.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/sports.yml",
"C:/Users/user/PycharmProjects/pythonProject/directory/trivia.yml"
]
cleaned_corpus = clean_corpus(file_list)
trainer.train(file_list)
I am not certain where or why it is giving me this error. I cannot seem to pinpoint it, however I sense it is in plain sight. Additionally, I am using the hugging-face BERT transformer. Any advice is welcome.
ChatterBotCorpusTrainer.train's signature doesn't accept a list, it takes *args. Relevant documentation example, and the source code of the signature.
Replace trainer.train(file_list) with trainer.train(*file_list).
Previos title was:
AttributeError: module 'json' has no attribute 'loads'
I changed it because it looks similar to this but at the link that i provided, the problem seems that the person was having a file called json.py that was tricking the import to think that is importing a local file and not the json from standard library. My problem is that I don't have any local file called json.py;
I am wondering if it has to do anything related to PATH or the structure of my project. Any suggestion might help.
error traceback:
File "D:\Me\IdeaProjects\src\app\repositories\user_repository.py", line 14, in get_user
user = json.loads(file.read())
I am running the code in Windows 10, and intelliJ ide.
Python version: 3.7.4
Tried the code from the official documentation this:
import json
def as_complex(dct):
if '__complex__' in dct:
return complex(dct['real'], dct['imag'])
return dct
json.loads('{"__complex__": true, "real": 1, "imag": 2}', object_hook=as_complex)
And got this error as well:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
json.loads('{"__complex__": true, "real": 1, "imag": 2}',object_hook=as_complex)
AttributeError: module 'json' has no attribute 'loads'
When I try to import loads explicitly i get this error:
ImportError: cannot import name 'loads' from 'json' (unknown location)
I had python installed in Admin account in window 10 and it was installed with Admin privileges, but when i used in another account I could not use the packages, however installing the python in the current account did fix the problem.
Try to import loads explicitly:
import json
from json import loads
I'm using python version 3.6.
mystuff.py includes:
mystuff = {'donut': "SHE LOVES DONUTS!"}
mystuffTest.py includes this
import mystuff
print (mystuff['donut'])
The error that I receive when I run mystuffTest.py is as follows:
$ python3.6 mystuffTrythis.py
Traceback (most recent call last):
File "mystuffTrythis.py", line 3, in <module>
print (mystuff['donut'])
TypeError: 'module' object is not subscriptable
So far I haven't seen this exact error here on stackoverflow. Can anyone explain why I am getting this error?
import mystuff is importing the module mystuff, not the variable mystuff. To access the variable you'd need to use:
import mystuff
print(mystuff.mystuff['donut'])
EDIT: It's also possible to import the variable directly, using:
from mystuff import mystuff
print(mystuff['donut'])
I got this error because a later from __ import * statement imported a module which bound my variable to something else:
from stuff_a import d
from stuff_b import *
d['key']
In stuff_b.py, d was bound to a module, hence the error. Lesson learned: avoid importing * from modules.
I am using Pickle in Python2.7. I am getting error while using cPickle.load() method. The code and error is shown below. Can someone guide me through this?
Code:
#! usr/bin/python
import cPickle
fo = open('result','rb')
dict1 = cPickle.load(fo)
Error:
Traceback (most recent call last):
File "C:\Python27\test.py", line 7, in <module>
dicts = cPickle.load(fo)
ImportError: No module named options
It seems like you can not do
import options
but when you or someone else did
cpickle.dump(xxx, open('result', 'rb'))
there was an object with a class or function of a module options that existed at this point in time, in xxx.
Solution
You can open the file binarily and replace options with the module you replaced the old module options with.
You probably created the file in your package like in module package.main by executing the file main.py or something like it, having a module options in the same directory.
Now you do import package.main, try to read the file and options is now called package.options and the module options can not be found.
How did you create this file? How do you load it now? cPickle/pickle does not transfer source code - so if you use a function you need the module when you load it.
FIXED: turns out there is a module already called parser. Renamed it and its working fine! Thanks all.
I got a python NameError I can't figure out, got it after AttributeError. I've tried what I know, can't come up with anything.
main.py:
from random import *
from xml.dom import minidom
import parser
from parser import *
print("+---+ Roleplay Stat Reader +---+")
print("Load previous DAT file, or create new one (new/load file)")
IN=input()
splt = IN.split(' ')
if splt[0]=="new":
xmlwrite(splt[1])
else:
if len(splt[1])<2:
print("err")
else:
xmlread(splt[1])
ex=input("Press ENTER to Exit...")
parser.py:
from xml.dom import minidom
from random import *
def xmlread(doc):
xmldoc = minidom.parse(doc)
itemlist = xmldoc.getElementsByTagName('item')
for s in itemlist:
print(s.attributes['name'].value,":",s.attributes['value'].value)
def xmlwrite(doc):
print("no")
And no matter what I get the error:
Traceback (most recent call last):
File "K:\Python Programs\Stat Reader\main.py", line 10, in <module>
xmlwrite.xmlwrite(splt[1])
NameError: name 'xmlread' is not defined
The same error occurs when trying to access xmlwrite.
When I change xmlread and xmlwrite to parser.xmlread and parser.xmlwrite I get:
Traceback (most recent call last):
File "K:\Python Programs\Stat Reader\main.py", line 15, in <module>
parser.xmlread(splt[1])
AttributeError: 'module' object has no attribute 'xmlread'
The drive is K:\ because it's my personal drive at my school.
If your file is really called parser.xml, that's your problem. It needs to be parser.py in order to work.
EDIT: Okay, since that wasn't your issue, it looks like you have a namespacing issue. You import your parser module twice when you use import parser and then from parser import *. The first form of it makes "parser" the namespace and the second form directly imports it, so in theory, you should have both parser.xmlwrite and xmlwrite in scope. It's also clearly not useful to import minidom in main.py since you don't use any minidom functionality in there.
If you clear up those and still have the issue, I would suggest looking at __ init __.py. If that still does nothing, it could just plain be a conflict with Python's parser module, you could substitute a name like myxmlparser.