Camelot: DeprecationError: PdfFileReader is deprecated
Asked Answered
M

8

28

I have been using camelot for our project, but since 2 days I got following errorMessage. When trying to run following code snippet:

import camelot
tables = camelot.read_pdf('C:\\Users\\user\\Downloads\\foo.pdf', pages='1')

I get this error:

DeprecationError: PdfFileReader is deprecated and was removed in PyPDF2 3.0.0. Use PdfReader instead.

I checked this file and it does use pdfFileReader: c:\ProgramData\Anaconda3\lib\site-packages\camelot\handlers.py

I thought that I can specify the version of PyPDF2, but it will be installed automatically(because the library is used by camelot) when I install camelot. Do you think there is any solution to specify the version of PyPDF2 manually?

Margie answered 28/12, 2022 at 11:35 Comment(2)
In the requirements of camelot is specified that it needs PyPDF2>=1.26.0. So as long as you install a version that satisfies that requirement, everything should be fine. An issue regarding this problem already exists on their GitHub.Oxa
you can try to manually install the package: pip install pypdf<3.0.0Midst
T
41

This is issues #339.

While there will hopefully be soon a release including the fix, you can still do this:

pip install 'PyPDF2<3.0'

after you've installed camelot.

See https://github.com/camelot-dev/camelot/issues/339#issuecomment-1367331630 for details and screenshots.

Torrell answered 30/12, 2022 at 0:19 Comment(5)
I tried pip install PyPDF2<3.0 in Colab but still received the error DeprecationError: PdfFileReader is deprecated and was removed in PyPDF2 3.0.0. Use PdfReader insteadIn
You still have PyPDF2>=3.0. This error message didn't exist before 3.0.Torrell
@ChristineTan I had this same issue. Double check your PyPDF2 version (pip3 show PyPDF2), and if less than 3.0, restart your kernel/venv and rerun your code.Silverstein
Issue still exists.Confucian
As camelot is dead, it will also not go away.Torrell
F
3

If anyone trying to do this on colab then run the following steps:

!pip install ghostscript
!pip install camelot-py[cv]
!pip install excalibur-py
!apt install ghostscript python3-tk

And after that check if installed:

from ctypes.util import find_library

# It will display `libgs.so.9` if installed or will print `None` if not
print(find_library("gs")) 

If still doesn't work:

!excalibur initdb

Source: here

Flax answered 25/5, 2023 at 5:36 Comment(0)
W
1
DeprecationError: PdfFileReader is deprecated and was removed in PyPDF2 3.0.0. Use PdfReader instead.

Just removing the file from pdfFileReader worked for me. This means writing this PdfReader instead of pdfFileReader this.

Wherefrom answered 2/5, 2023 at 7:38 Comment(1)
Please explain with a block of code for easier comprehension.Pteropod
S
0

I just changed the imports as the error msg suggested:

# From
from PyPDF2 import PdfFileMerger
from PyPDF2 import PdfFileReader

# To
from PyPDF2 import PdfMerger
from PyPDF2 import PdfReader

In my case (version PyPDF2 3.0.0) both classes exists. And I thought that I need to change the code or something, but no, simply worked.

Smash answered 29/4, 2023 at 21:1 Comment(0)
P
0

On M2 Mac this worked -

  1. brew install ghostscript tcl-tk
  2. pip install camelot-py[base]
  3. pip install 'PyPDF2<3.0'
Piles answered 6/12, 2023 at 17:18 Comment(0)
P
0

Okay camelot installation was a bit of pain:

Here is what is worked for me on windows 10 with python 3.11 64bit

WHAT NOT TO DO:

  1. Do NOT RUN pip install camelot if you have already done it remove it by running pip uninstall camelot (Its a different package)
  2. Do NOT RUN pip install camelot-py if you have already done it remove it by running pip uninstall camelot-py (It will install camelot without the dependencies)
  3. Do NOT RUN pip install camelot-py[all] if you have already done it remove it by running pip uninstall camelot-py[all] (It will intall the older version camelot-py-0.9.0 which contains Depraceted code )

WHAT TO DO:

  1. pip install camelot-py[cv2]
  2. Verify installed version, should be camelot-py-0.11.0 or newer
  3. Restart python
  4. Install Ghostscript (https://camelot-py.readthedocs.io/en/master/user/install-deps.html#install-deps)
  5. Add the folowing paths to your PATH var:

C:\Program Files\gs\gs{you gs ver here}\lib

C:\Program Files\gs\gs{you gs ver here}\bin

  1. Run pip install ghostscript

  2. Restart python

  3. import camelot -->Grats you are finally Done!

Note: Steps 4-7 only needed if you would like to use lattice mode for stream mode you only need steps 1-3

According to the docs you might also need activetcl see (https://camelot-py.readthedocs.io/en/master/user/install-deps.html#install-deps) i have not installed it.

Protomorphic answered 22/3 at 1:54 Comment(1)
You also need to install opencv pip install opencv-pythonProtomorphic
B
0

You probably have PyPDF2 3.0 or above installed. You have to uninstall that and install a previous version.

pip uninstall PyPDF2 pip install PyPDF2==1.26.0

Belonging answered 6/6 at 21:26 Comment(0)
T
-2

I solved the issue uninstalling camelot-py and re installing it includeing the "extra cv requirement", like this:

pip install "camelot-py[base]"

I hope it can be useful!

source: https://readthedocs.org/projects/camelot-py/downloads/pdf/master/

Transarctic answered 17/3, 2023 at 9:34 Comment(2)
You don't need to Uninstaller. Just upgrade with - -upgradeTorrell
There is already an answer. Check out thisMargie

© 2022 - 2024 — McMap. All rights reserved.