12

Im trying to use tabula-py to transfer a table from pdf to excel.

When im trying to

from tabula import read_pdf

it says

ImportError: cannot import name 'read_pdf'

All solutions i found say that i have to

pip uninstall tabula
pip3 install tabula-py

https://github.com/chezou/tabula-py/issues/47

Tabula-py - ImportError: No module named tabula

But its still not working for me.

Any ideas?

DanielHe
  • 179
  • 1
  • 3
  • 10

9 Answers9

11

Maybe this is because of the version of tabula you installed.

If you installed tabula by running:

pip install tabula

You get an old version of tabula (1.0.5) that has the problem with the module .read_pdf(). To fix the problem and get a newer version of tabula, first:

uninstall tabula with the command:

pip uninstall tabula

And install the newer version of tabula with the command:

pip install tabula-py

I think this will solve your problem.

ujjal das
  • 897
  • 11
  • 15
  • It also solved my problem. However, the important thing was that I had to close CMD, and open again, and run a fresh jupyter notebook (simply restarting jupyter notebook did not work). – mah65 Nov 08 '20 at 00:01
  • 2
    This did not immediately solve my problem because, I think, I had both `tabula` and `tabula-py` install. I had to uninstall both then reinstall `tabula-py` by itself to get it to work. – Mauricio Feb 15 '22 at 19:20
6
from tabula import wrapper
df = wrapper.read_pdf('my_pdf')

read_pdf is contained within 'wrapper'. Hence you import wrapper and call read_pdf from wrapper.

Jay Haran
  • 123
  • 1
  • 9
  • 2
    Please consider adding some explanation to your answer. – HMD Apr 24 '18 at 09:00
  • I believe the issue arises becuase of tabula updating the method. Now the method read_pdf sits inside of wrapper. – geekidharsh Jan 10 '19 at 23:09
  • nope, it doesn't solve the problem, an error comes up : _cannot import name 'wrapper' from 'tabula' (/usr/local/lib/python3.7/site-packages/tabula/__init__.py)_ – yts61 Mar 04 '20 at 08:47
  • 1
    It doesn't work. ImportError: cannot import name 'wrapper' from 'tabula' (/tmp/yes/lib/python3.7/site-packages/tabula/__init__.py) – Strayhorn Mar 11 '20 at 13:58
4

I solved as follows:

  1. upgrade pip to pi3: pip install --upgrade pip --user

pip3 uninstall tabula-py

pip3 install tabula-py

That solved the problem perfectly! Good luck!

2

There is a chance that you're testing tabula-py within a module you named tabula.py

This would throw the same exact error because of module import order in Python

Abdulrahman Bres
  • 2,603
  • 1
  • 20
  • 39
1

It worked for me when I have installed it with pip install tabula-py

Piyush S. Wanare
  • 4,703
  • 6
  • 37
  • 54
JON
  • 1,668
  • 2
  • 15
  • 18
1

Yes! I had this same problem. The file I was using to write the code was named 'tabula.py'. I wrote the code in a new file, with a new name, and had to delete the file named 'tabula.py'.

Once I did that the error went away.

1
Step 1:- Upgrade PIP
 python.exe -m pip install --upgrade pip --u

Step2 : make sure its upgraded in your virtual environment
(venv) D:\dMig\venv\Lib\site-packages>pip install --upgrade pip --user
Requirement already up-to-date: pip in d:\python38\lib\site-packages (20.2)

Step3: Uninstall earlier version 
(venv) D:\dMig\venv\Lib\site-packages>pip3 uninstall tabula-py

Step4: Install again
pip3 install tabula-py

Step5: Verify by below code

from tabula import read_pdf

#declare the path of your file
file_path = "E:\Activity.pdf"

#Convert your file
df = read_pdf(file_path)
print(df)
0

Easy Solution - 1- uninstall the old tabula

pip uninstall tabula

2- install the new tabula-py

pip install tabula-py

then use the module

from tabula import read_pdf
sameer_nubia
  • 721
  • 8
  • 8
-1

try:

from tabula.io import read_pdf
df = read_pdf('file.pdf', pages='all')