Runtime error~import cv2
Describe the bug
Traceback (most recent call last):
File "/home/kali/Documents/PDF-Table-Exctractor/reader.py", line 1, in
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
Any update on this? getting same error on MacOs Monterey
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.
This worked for me. Changing import in image_processing.py to:
try:
import cv2
except:
import opencv as cv2
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.
I think this is a duplicate of https://github.com/camelot-dev/camelot/issues/286
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?
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.
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.