AttributeError: module 'camelot' has no attribute 'read_pdf'
Asked Answered
M

9

17

I am trying to extract tables from pdf using camelot and I get this attribute error. Could you please help?

import camelot
import pandas as pd
pdf = camelot.read_pdf("Gordian.pdf")

AttributeError Traceback (most recent call last) in ----> 1 pdf = camelot.read_pdf("Gordian.pdf")

AttributeError: module 'camelot' has no attribute 'read_pdf'

Mirabelle answered 14/10, 2019 at 12:15 Comment(2)
Please read github.com/atlanhq/camelot/issues/118 and github.com/atlanhq/camelot/issues/145. If you don't find a solution, post the output of the command dir(camelot)Merrimerriam
you may have probably installed camleot instead of camelot-pyMaxantia
R
18

NOTE : If you are using virtual environment activate environment before do this things.

I have already faced this error.There is a no bug in your code.The problem is with camelot installation.

1 remove installed camelot version

2 install again using this command. There is a multiple ways to install camelot. Please try it one by one

  • pip install camelot-py
  • pip install camelot-py[cv]
  • pip install camelot-py[all]

3 run your code >> i have attached sample code here

import camelot

data = camelot.read_pdf("test_file.pdf", pages='all')
print(data)
Redress answered 23/10, 2019 at 9:19 Comment(2)
It will work on python editor eg: pycharmRedress
This did not work for me unfortunately. So commenting so future users can assess.Anderton
L
9

Try this: import camelot.io as camelot That worked for me.

Latashialatch answered 13/3, 2021 at 3:16 Comment(0)
I
4

please check if you have java installed on you machine, go to your terminal and run "java -version", if you do not have you won't be able to read pdf using Camelot or tabula,

once you have installed java, install tabula-py using the command pip install tabula-py.

from tabula.io import read_pdf
tables = read_pdf('file.pdf')  # substitute your file name
Inward answered 26/6, 2021 at 18:28 Comment(0)
M
4

I abandoned trying to get camelot to work in Jupiter Notebooks to read tables & instead installed the following:

!{sys.executable} -m pip install tabula-py tabulate

from tabula import read_pdf
from tabulate import tabulate


pdf_path = (
    Path.home()
    / "my_pdf.pdf"
)
df = read_pdf(str(pdf_path), pages=1)
df[0]
Mireyamiriam answered 26/7, 2021 at 12:50 Comment(0)
P
1

Here's the link with full installation steps: https://camelot-py.readthedocs.io/en/master/user/install.html#using-pip

After you install

pip install camelot-py[cv]

Write this:

import camelot.io as camelot
Pledgee answered 16/9, 2021 at 22:47 Comment(1)
I think that most user do pip install camelot which installs something else entirely: pypi.org/project/CamelotAnders
E
0

pip uninstall camelot pip uninstall camelot-py pip install camelot-py[cv]

install ghostscript app from internet

! apt install ghostscript python3-tk pip install ghostscript

Eugeniaeugenics answered 11/11, 2022 at 20:36 Comment(0)
R
0

I believe most of the answers here are all correct. However, the confusion lies in the name of the library. There are two Camelot libraries in pycharm.

If you are looking for PDF table extraction, it is called camelot-py NOT Camelot

and then add import camelot.io as camelot

If you confused the two libraries, importing camelot.io will not work.

If it still give you an error. Try removing Camelot from the project interpreter. That worked for me.

Retinoscope answered 4/2 at 12:24 Comment(0)
A
0

I had an error like this. It opened that I was stupid enough to create a test script 'camelot.py' that was trying to import module camelot :-) Renaming helped. The same was for tabula.

Accentuate answered 25/7 at 9:19 Comment(0)
L
-1

When downloading the library please pay attention to where it is downloaded. Because the library you downloaded may have been saved in another Python version

Lariat answered 17/1, 2021 at 12:31 Comment(1)
Hello and welcome to SO! Please read the tour, and How do I write a good answer? For example you can elaborate how to pay this kind of attention, what would you expect ti find, annd how it should be fixed.Declared

© 2022 - 2024 — McMap. All rights reserved.