5

I am trying to use Tabula-py to read a pdf. I installed tabula-py through pip install tabula-py

I have also installed the required dependencies

requests
pandas
pytest
flake8

My code is currently as follows:

import tabula
import pandas as pd

df = tabula.read_pdf("report.pdf", pages=2)
print(df)

I am getting the following error:

Traceback (most recent call last):
File "tabula_pdf_reader.py", line 1, in <module>
  import tabula
ImportError: No module named tabula

Any inputs to what I am missing here?

AgentX
  • 1,402
  • 3
  • 23
  • 38
  • Looks like your install of tabula failed. You are getting a failure on the `import` statement. That means the interpreter disagrees with your view that you have installed it. – BoarGules Aug 09 '17 at 17:15
  • 1
    `pip install tabula-py` gives `Requirement already satisfied: tabula-py in /usr/local/lib/python2.7/site-packages`, so I assume that it is correctly installed? – AgentX Aug 09 '17 at 17:36
  • 2
    Do you maybe have more than one Python environment? The only thing I can think of that would cause what you describe is if you installed tabula in 2.7 but are importing it in a 3.6 interpreter session. – BoarGules Aug 09 '17 at 17:42
  • I do have 2 python environments. But I am running it through terminal which is using 2.7. I verified this by `which python` which gave `/usr/bin/python` and then I checked the version `/usr/bin/python -version` which gave 2.7 – AgentX Aug 10 '17 at 01:28
  • Well I installed tabula-py for python3 and ran it with python3 and it worked. Looks like some python2 specific issue on my end. – AgentX Aug 10 '17 at 01:48

4 Answers4

2

I faced this same issue in Ubuntu.

First, check the version of the JDK and JRE that are installed on your machine by running java --version and javac --version. Each should have a version greater than 7.

Then use pip3 to install tabula.

chb
  • 1,727
  • 7
  • 25
  • 47
Jaikishore
  • 111
  • 2
  • 6
2

I got the same issue here when executing on Terminal. However, after I ran by starting with 'ipython3' instead of 'ipython', it worked perfectly. You have to make sure that tabula-py module is installed in python3 directory, not python2

thp
  • 45
  • 1
  • 6
1

use this

 import camelot
 tables = camelot.read_pdf('foo.pdf')
 tables.export('foo.csv', f='csv', compress=True)
Ganesh Kharad
  • 333
  • 2
  • 6
  • 1
    While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context. – Dima Kozhevin May 10 '19 at 12:38
0

For macOS users - an update to Monterey operating system will solve the problem.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 17 '22 at 23:57