camelot icon indicating copy to clipboard operation
camelot copied to clipboard

Runtime error~import cv2

Open paulfruitful opened this issue 3 years ago • 8 comments

Describe the bug Traceback (most recent call last): File "/home/kali/Documents/PDF-Table-Exctractor/reader.py", line 1, in import camelot File "/usr/local/lib/python3.10/dist-packages/camelot/init.py", line 6, in from .io import read_pdf File "/usr/local/lib/python3.10/dist-packages/camelot/io.py", line 5, in from .handlers import PDFHandler File "/usr/local/lib/python3.10/dist-packages/camelot/handlers.py", line 9, in from .parsers import Stream, Lattice File "/usr/local/lib/python3.10/dist-packages/camelot/parsers/init.py", line 4, in from .lattice import Lattice File "/usr/local/lib/python3.10/dist-packages/camelot/parsers/lattice.py", line 26, in from ..image_processing import ( File "/usr/local/lib/python3.10/dist-packages/camelot/image_processing.py", line 3, in import cv2 ModuleNotFoundError: No module named 'cv2'

Steps to reproduce the bug

Expected behavior

Code

import camelot

print('''################################################################
 $$$$$$__ $$$$$___ $$$$$$$_
$$___$$_ $$__$$__ $$______
$$___$$_ $$___$$_ $$$$$___
$$$$$$__ $$___$$_ $$______
$$______ $$__$$__ $$______
$$______ $$$$$___ $$______
################################################################''')
#'''

tables = camelot.read_pdf('foo.pdf')

tables
tables.export('foo.csv', f='csv', compress=True) # json, excel, html, markdown, sqlite

tables[0]

tables[0].parsing_report
{
    'accuracy': 99.02,
    'whitespace': 12.24,
    'order': 1,
    'page': 1
}

tables[0].to_csv('foo.csv') # to_json, to_excel, to_html, to_markdown, to_sqlite


# add your code here

Environment

  • OS: Kali Linux
  • Python version: Latest
  • Numpy version:Latest
  • OpenCV version:Latest
  • Ghostscript version:Latest
  • Camelot version:Latest

Additional context

paulfruitful avatar Aug 30 '22 00:08 paulfruitful

Any update on this? getting same error on MacOs Monterey

euler007 avatar Sep 04 '22 10:09 euler007

Any update on this? getting same error on MacOs Monterey

No update on this yet, I am still struggling to figure out what's wrong.

paulfruitful avatar Sep 04 '22 22:09 paulfruitful

This worked for me. Changing import in image_processing.py to:

try:
     import cv2
except:   
     import opencv as cv2

phoebebright avatar Jan 04 '23 12:01 phoebebright

I got this as well on MacOS 12 Monterey, Python 3.9, camelot 0.10.1. Looks like on the Mac at least there's a possibly related cv2 bug on MacOS 11 BigSur: opencv-python: https://github.com/opencv/opencv-python/issues/777

I tried downgrading to opencv-python<3.7 in my requirements.txt file, and that seemed to solve the cv2 import issue, although I'm still working through other problems.

YKdvd avatar Feb 20 '23 12:02 YKdvd

I think this is a duplicate of https://github.com/camelot-dev/camelot/issues/286

Lucas-C avatar Mar 27 '23 06:03 Lucas-C

This worked for me. Changing import in image_processing.py to:

try:
     import cv2
except:   
     import opencv as cv2

I still get an error: import opencv as cv2 ModuleNotFoundError: No module named 'opencv'

Is opencv a pip module or something like that?

MartinMohammed avatar May 10 '23 18:05 MartinMohammed

For @MartinMohammed :

The name of the package on PyPi and hence also for a pip command is opencv-python or opencv-python-headless

The name of the module implemented by that package and required by Camelot is cv2.

So pip install opencv-python-headless to install the package - or you will need to do whatever is equivalent in your environment to add a package. (For instance I am using requirements.txt and a virtual environment.)

And no need for any specific code in your project, because the Camelot library already includes the import statement import cv2.

The discussion above seems like it's some sort of version control issue in the python environment for @paulfruitful 's Linux environment and in a separate issue, in a Monterey MacOS environment for @euler007 and @YKdvd.

So for @MartinMohammed just get opencv-python-headless installed and see how far you get.

I will see if I can unpick the Mac issue a little bit and comment again if I get anywhere - I do remember getting into dependency hell last time I was tinkering with this.

ghost avatar May 23 '23 11:05 ghost

I'm getting the same issue here on Windows 10 Pro with Python 3.12. I'll try some of the suggestions above. The camelot instructions at https://pypi.org/project/camelot-py/ do not mention installing opencv-python.

Jinkies! Installing opencv-python-headless is 35MB.

bulrush15 avatar Apr 23 '24 12:04 bulrush15