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

Error in reading tables in pdf even though ghostscript is installed #408

Open
KanduriR opened this issue Mar 5, 2020 · 4 comments
Open

Comments

@KanduriR
Copy link

KanduriR commented Mar 5, 2020

Hi I am trying to read tables in a pdf with multiple columns, and this is the output error I get.

Type "help", "copyright", "credits" or "license" for more information.
>>> import camelot
>>> tables = camelot.read_pdf('/Users/sgudisa/Desktop/FashionReport_2019_46-63.pdf')
Traceback (most recent call last):
  File "//anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/_gsprint.py", line 251, in <module>
    libgs = cdll.LoadLibrary("libgs.so")
  File "//anaconda3/lib/python3.7/ctypes/__init__.py", line 434, in LoadLibrary
    return self._dlltype(name)
  File "//anaconda3/lib/python3.7/ctypes/__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libgs.so, 6): image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "//anaconda3/lib/python3.7/site-packages/camelot/io.py", line 117, in read_pdf
    **kwargs
  File "//anaconda3/lib/python3.7/site-packages/camelot/handlers.py", line 172, in parse
    p, suppress_stdout=suppress_stdout, layout_kwargs=layout_kwargs
  File "//anaconda3/lib/python3.7/site-packages/camelot/parsers/lattice.py", line 403, in extract_tables
    self._generate_image()
  File "//anaconda3/lib/python3.7/site-packages/camelot/parsers/lattice.py", line 212, in _generate_image
    from ..ext.ghostscript import Ghostscript
  File "//anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/__init__.py", line 24, in <module>
    from . import _gsprint as gs
  File "//anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/_gsprint.py", line 258, in <module>
    raise RuntimeError("Please make sure that Ghostscript is installed")
RuntimeError: Please make sure that Ghostscript is installed
>>> gs -version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'gs' is not defined
>>> exit()

(base) Srujans-MacBook-Air:~ sgudisa$ gs -version
GPL Ghostscript 9.22 (2017-10-04)
Copyright (C) 2017 Artifex Software, Inc.  All rights reserved.
(base) Srujans-MacBook-Air:~ sgudisa$ 

I see two errors in the output, an OSERRO 'dlopen : image not found' and other is the ghostscript not available. I've checked using the gs -version command and I see that ghostscript being available. Attaching the pdf file that I am trying to readout. So far i understand that the lattice option can read out the pdf tables but I couldn't even come upto there.

FashionReport_2019_46-63.pdf

@AsgerPetersen
Copy link

I get this error too on OSX with the following conda 4.8.3 environment:

conda create -n camelot
conda activate camelot
conda install -c conda-forge camelot-py
python

and then in python:

import camelot
f = "file.pdf"
tables = camelot.read_pdf(f)

It seems to be independent of the pdf file used.

@chfw
Copy link

chfw commented Oct 11, 2020

It is related to this SO post: https://stackoverflow.com/questions/6848903/python-ghostscript-runtimeerror-can-not-find-ghostscript-library-libgs

I have to hack camelot/ext/ghostscript/_gsprint.py

else:
    try:
        libgs = cdll.LoadLibrary("libgs.so")
    except OSError:
        # shared object file not found
        import ctypes.util

        libgs = ctypes.util.find_library("/usr/local/Cellar/ghostscript/9.53.3/lib/libgs")  # <-- hack
        if not libgs:
            raise RuntimeError("Please make sure that Ghostscript is installed")
        libgs = cdll.LoadLibrary(libgs)

@chfw
Copy link

chfw commented Oct 11, 2020

please try: 'which gs' and figure out where your libgs is and do the back. that's my two cents.

@chfw
Copy link

chfw commented Oct 11, 2020

please evaluate this PR: #426 too. It worked for me and I can remove my hack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants