attempting to read pdf results in "OSError: Ghostscript is not installed" but it is

Viewed 540

Trying to run a basic script:

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

results in:

Traceback (most recent call last):
  File "C:\Users\username\Documents\GitHub\Scott\test_files\pdf_extract.py", line 2, in <module>
    tables = camelot.read_pdf('foo.pdf')
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\camelot\io.py", line 113, in read_pdf
    tables = p.parse(
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\camelot\handlers.py", line 176, in parse
    t = parser.extract_tables(
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\camelot\parsers\lattice.py", line 421, in extract_tables
    self.backend.convert(self.filename, self.imagename)
  File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\camelot\backends\ghostscript_backend.py", line 30, in convert
    raise OSError(
OSError: Ghostscript is not installed. You can install it using the instructions here: https://camelot-py.readthedocs.io/en/master/user/install-deps.html
[Finished in 1.3s]

Running Windows 10 OS, Python 3.9.2. script is being run using sublime text.

I've installed both 32 and 64 bit versions of Ghostscript (gs9.55), added path statements to both bin and lib directories and checked the dll is registered in the registry. No luck.

Funny thing: when I run the commands line by line from the python command line, it works! Running:

>>> import ctypes
>>> from ctypes.util import find_library
>>> find_library("".join(("gsdll", str(ctypes.sizeof(ctypes.c_voidp) * 8), ".dll")))

Produces - 'C:\Program Files\gs\gs9.55.0\bin\gsdll64.dll' so the library is there.
I just discovered if I comment out this part in ghostscript_backend.py:

def convert(self, pdf_path, png_path, resolution=300):
        # if not self.installed():
        #     raise OSError(
        #         "Ghostscript is not installed. You can install it using the instructions"
        #         " here: https://camelot-py.readthedocs.io/en/master/user/install-deps.html"
        #     )

The script works and then I can move on to getting tables and such. Is there a newer version of the ghostscript_backend.py I should be using?

0 Answers
Related