Python3 : module 'tabula' has no attribute 'read_pdf'

Viewed 27091

A .py program works but the exact same code, when exposed as API, doesn't work.

The code reads the pdf with Tabula and provides the table content as a output.

I've tried :

import tabula
df = tabula.read_pdf("my_pdf")
print(df)

and

from tabula import wrapper
df = wrapper.read_pdf("my_pdf")
print(df)

I've installed tabula-py (not tabula) on AWS EC2 running Ubuntu.

More than read_pdf, I actually want to convert to CSV and give the output. But that doesn't work as well. I get the same no-attribute error i.e. module 'tabula' has no attribute 'convert_into.

The .py file and the API file (.py as well) are in the same directory and are accessed with the same user.

Any help will be highly appreciated.

EDIT : I tried to run the same python file from the API as OS command (os.system("python3 /home/ubuntu/flaskapp/tabler.py")). But it didn't work as well.

8 Answers

make sure that you installed tabula-py not just tabula use

!pip install tabula-py

and to import it use

from tabula.io import read_pdf

There is actually an entry in the FAQ about this issue specifically :

If you’ve installed tabula, it will be conflict the namespace. You should install tabula-py after removing tabula.

Although using read_csv() from tabula.io worked, as suggested by other answers, I was also able to use tabula.read_csv() after having removed tabula and reinstalled tabula-py (using pip install --force-reinstall tabula-py).

If you accidentally installed tabula before installing tabula-py, they'll conflict in the namespace (even after uninstalling tabula).

Uninstall tabula-py and re-install it. That did the trick for me.

There is something off with tabula package. I looked inside and there is no __init__.py. You can do:

from tabula.io import read_pdf

it worked for me.

from tabula import read_pdf didn't work for me. I've replaced tabula.read_pdf() by tabula.io.read_pdf() to make it work.

if you are working in colab then u have to install it by command

!pip install -q tabula-py import tabula

and for using function like read_pdf and convert_into we have to use dfs = tabula.io.read_pdf(path, stream=True)

Note-tabula.io (should be used to access these function in colab) have a good day and long live Data science community.

try

from tabula import read_pdf

I had the same problem, and this fixed it.

It is working this way:

import tabula # just this here!

#declare the path of your file
file_path = "/path/to/pdf_file/data.pdf"

#Convert your file
df = tabula.io.read_pdf(file_path)

Thai is all!

Related