Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error~import cv2 #326

Open
paulfruitful opened this issue Aug 30, 2022 · 8 comments
Open

Runtime error~import cv2 #326

paulfruitful opened this issue Aug 30, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@paulfruitful
Copy link

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 paulfruitful added the bug Something isn't working label Aug 30, 2022
@euler007
Copy link

euler007 commented Sep 4, 2022

Any update on this? getting same error on MacOs Monterey

@paulfruitful
Copy link
Author

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.

@phoebebright
Copy link

phoebebright commented Jan 4, 2023

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

try:
     import cv2
except:   
     import opencv as cv2

@YKdvd
Copy link

YKdvd commented Feb 20, 2023

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: opencv/opencv-python#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.

@Lucas-C
Copy link
Contributor

Lucas-C commented Mar 27, 2023

I think this is a duplicate of #286

@MartinMohammed
Copy link

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?

@ghost
Copy link

ghost commented May 23, 2023

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.

@bulrush15
Copy link

bulrush15 commented Apr 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants