camelot icon indicating copy to clipboard operation
camelot copied to clipboard

RuntimeError: Please make sure that Ghostscript is installed

Open rafiepstein opened this issue 5 years ago • 87 comments

Hello, Trying to run a single line: (Python 2.7.15 under Pycharm)

import camelot
tables = camelot.read_pdf(inpFile)

Full Stack: C:\Python27\python.exe "C:\Program Files\JetBrains\PyCharm 2018.2.2\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 51131 --file C:/Users/Rafi/Documents/re_FOCUS/StrataVAR/Python/testPDFTables.py pydev debugger: process 8344 is connecting

Connected to pydev debugger (build 183.5429.31) Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm 2018.2.2\helpers\pydev\pydevd.py", line 1741, in main() File "C:\Program Files\JetBrains\PyCharm 2018.2.2\helpers\pydev\pydevd.py", line 1735, in main globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files\JetBrains\PyCharm 2018.2.2\helpers\pydev\pydevd.py", line 1135, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:/Users/Rafi/Documents/re_FOCUS/StrataVAR/Python/testPDFTables.py", line 24, in tables = camelot.read_pdf(inpFile) File "C:\Python27\lib\site-packages\camelot\io.py", line 106, in read_pdf layout_kwargs=layout_kwargs, **kwargs) File "C:\Python27\lib\site-packages\camelot\handlers.py", line 162, in parse layout_kwargs=layout_kwargs) File "C:\Python27\lib\site-packages\camelot\parsers\lattice.py", line 351, in extract_tables self._generate_image() File "C:\Python27\lib\site-packages\camelot\parsers\lattice.py", line 186, in generate_image from ..ext.ghostscript import Ghostscript File "C:\Python27\lib\site-packages\camelot\ext\ghostscript_init.py", line 24, in from . import _gsprint as gs File "C:\Python27\lib\site-packages\camelot\ext\ghostscript_gsprint.py", line 229, in raise RuntimeError('Please make sure that Ghostscript is installed') RuntimeError: Please make sure that Ghostscript is installed

Process finished with exit code 1

Windows-10-10.0.17763 ('Python', '2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (Intel)]') ('NumPy', '1.16.1') ('OpenCV', '4.0.0') ('Camelot', '0.7.2')

Ghostscript 64 installed under Win10 64 bit:

C:\Users\Rafi>gswin64c.exe -version GPL Ghostscript 9.26 (2018-11-20) Copyright (C) 2018 Artifex Software, Inc. All rights reserved.

There is a path to C:\Program Files\gs\gs9.26\bin and to C:\Program Files\gs\gs9.26\bin.

Tracking the source of the Python exception, it seems that the code in __win32_finddll(): fails to find the Registry key.

Using Regedit, there is a key: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\GPL Ghostscript\9.26 with two entries GS_DLL: C:\Program Files\gs\gs9.26\bin\gsdll64.dll and GS_LIB - C:\Program Files\gs\gs9.26\bin;C:\Program Files\gs\gs9.26\lib;C:\Program Files\gs\gs9.26\fonts

The statement QueryInfoKey(k1) returns (in _gsprint.py) (0, 0, 131955508546095202L), thus range(0,0) is [] and the loop fails, so the function returns None.

Any suggestions? Thanks, --Rafi

rafiepstein avatar Feb 25 '19 08:02 rafiepstein

Did you try the solutions mentioned in #184?

vinayak-mehta avatar Mar 08 '19 14:03 vinayak-mehta

Hello Vinayak, I am not sure what you mean by "solution mentioned"... As far as I could tell, no solution relevant to Windows environment is mentioned. Ghoscript is installed as per the test suggested. PATH is setup correctly. The problem seems to be in _gsprint.py, line: for num in range(0, QueryInfoKey(k1)[0]): as QueryInfoKey(k1) (0, 0, 131955739057984515L) thus range(0, QueryInfoKey(k1)[0]) is empty, and it doesn not find the dll.

Any suggestions?

rafiepstein avatar Mar 09 '19 12:03 rafiepstein

I'm having a similar issue, and couldn't solve it using the solutions mentioned in #184. I'd appreciate any suggestions.

Environment Darwin-17.7.0-x86_64-i386-64bit Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 02:16:08) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] NumPy 1.16.2 OpenCV 3.4.4 Camelot 0.7.1 Ghostscript 9.22

I'm using the foo.pdf from the documentation.

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

And getting the error message:


OSError Traceback (most recent call last) ~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/ext/ghostscript/_gsprint.py in 232 try: --> 233 libgs = cdll.LoadLibrary('libgs.so') 234 except OSError:

~/anaconda3/envs/camelot/lib/python3.6/ctypes/init.py in LoadLibrary(self, name) 425 def LoadLibrary(self, name): --> 426 return self._dlltype(name) 427

~/anaconda3/envs/camelot/lib/python3.6/ctypes/init.py in init(self, name, mode, handle, use_errno, use_last_error) 347 if handle is None: --> 348 self._handle = _dlopen(self._name, mode) 349 else:

OSError: dlopen(libgs.so, 6): image not found

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last) in ----> 1 tables = camelot.read_pdf('foo.pdf')

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/io.py in read_pdf(filepath, pages, password, flavor, suppress_stdout, layout_kwargs, **kwargs) 104 kwargs = remove_extra(kwargs, flavor=flavor) 105 tables = p.parse(flavor=flavor, suppress_stdout=suppress_stdout, --> 106 layout_kwargs=layout_kwargs, **kwargs) 107 return tables

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/handlers.py in parse(self, flavor, suppress_stdout, layout_kwargs, **kwargs) 159 for p in pages: 160 t = parser.extract_tables(p, suppress_stdout=suppress_stdout, --> 161 layout_kwargs=layout_kwargs) 162 tables.extend(t) 163 return TableList(tables)

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/parsers/lattice.py in extract_tables(self, filename, suppress_stdout, layout_kwargs) 349 return [] 350 --> 351 self._generate_image() 352 self._generate_table_bbox() 353

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/parsers/lattice.py in _generate_image(self) 184 185 def _generate_image(self): --> 186 from ..ext.ghostscript import Ghostscript 187 188 self.imagename = ''.join([self.rootname, '.png'])

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/ext/ghostscript/init.py in 22 # 23 ---> 24 from . import _gsprint as gs 25 26

~/anaconda3/envs/camelot/lib/python3.6/site-packages/camelot/ext/ghostscript/_gsprint.py in 238 libgs = ctypes.util.find_library('gs') 239 if not libgs: --> 240 raise RuntimeError('Please make sure that Ghostscript is installed') 241 libgs = cdll.LoadLibrary(libgs) 242

RuntimeError: Please make sure that Ghostscript is installed

tal-yifat avatar Mar 11 '19 11:03 tal-yifat

I have the same issue with the standalone version of Ghostscript (install version is not allowed due to the IT policy in my company). I had set the bin and lib directories of the Ghostscript (standalone) in PATH but Camelot is still trying to find the Ghostscript from the Windows registry.

QCTW avatar Mar 12 '19 15:03 QCTW

In macos brew install ghostscript

pantuts avatar Mar 17 '19 08:03 pantuts

In my case, Ghostscript is successfully installed. Shouldn't this be a bug?

tal-yifat avatar Mar 18 '19 15:03 tal-yifat

Ghostscript is successfully installed. Shouldn't this be a bug? yes it is a bug!!!!!

KAIXIE avatar Mar 25 '19 03:03 KAIXIE

I'll look into this over the weekend.

vinayak-mehta avatar Apr 12 '19 12:04 vinayak-mehta

exact same issue as well. I have the same issue with the standalone version of Ghostscript (install version is not allowed due to the IT policy in my company). I had set the bin and lib directories of the Ghostscript (standalone) in PATH but Camelot is still trying to find the Ghostscript from the Windows registry.

wangxiangtao avatar Apr 16 '19 15:04 wangxiangtao

I currently don't have a Windows machine to reproduce this, let me install it on my current laptop. I believe we should just try to get rid of ghostscript with #96.

vinayak-mehta avatar Apr 20 '19 15:04 vinayak-mehta

Same issue here

GuillaumeDesforges avatar Apr 23 '19 12:04 GuillaumeDesforges

Same for me. Even if i install ghostscript and python3-ghostscript via pip. macOS with PyCharm. Both latest versions.

marcoloew333 avatar Apr 30 '19 21:04 marcoloew333

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

daudna avatar May 07 '19 06:05 daudna

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

My code is now having no issues, too, thank you

ghost avatar May 30 '19 02:05 ghost

I have the same issue. Although I've tried other install method to install ghost script, it still does not work...


OSError Traceback (most recent call last) ~/anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/_gsprint.py in 232 try: --> 233 libgs = cdll.LoadLibrary('libgs.so') 234 except OSError:

~/anaconda3/lib/python3.7/ctypes/init.py in LoadLibrary(self, name) 433 def LoadLibrary(self, name): --> 434 return self._dlltype(name) 435

~/anaconda3/lib/python3.7/ctypes/init.py in init(self, name, mode, handle, use_errno, use_last_error) 355 if handle is None: --> 356 self._handle = _dlopen(self._name, mode) 357 else:

OSError: dlopen(libgs.so, 6): image not found

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last) in ----> 1 endmill_table_list_YG1 = camelot.read_pdf('ALU_endmill.pdf') 2 for table in endmill_table_list_YG1: 3 print(table.parsing_report)

~/anaconda3/lib/python3.7/site-packages/camelot/io.py in read_pdf(filepath, pages, password, flavor, suppress_stdout, layout_kwargs, **kwargs) 104 kwargs = remove_extra(kwargs, flavor=flavor) 105 tables = p.parse(flavor=flavor, suppress_stdout=suppress_stdout, --> 106 layout_kwargs=layout_kwargs, **kwargs) 107 return tables

~/anaconda3/lib/python3.7/site-packages/camelot/handlers.py in parse(self, flavor, suppress_stdout, layout_kwargs, **kwargs) 160 for p in pages: 161 t = parser.extract_tables(p, suppress_stdout=suppress_stdout, --> 162 layout_kwargs=layout_kwargs) 163 tables.extend(t) 164 return TableList(tables)

~/anaconda3/lib/python3.7/site-packages/camelot/parsers/lattice.py in extract_tables(self, filename, suppress_stdout, layout_kwargs) 349 return [] 350 --> 351 self._generate_image() 352 self._generate_table_bbox() 353

~/anaconda3/lib/python3.7/site-packages/camelot/parsers/lattice.py in _generate_image(self) 184 185 def _generate_image(self): --> 186 from ..ext.ghostscript import Ghostscript 187 188 self.imagename = ''.join([self.rootname, '.png'])

~/anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/init.py in 22 # 23 ---> 24 from . import _gsprint as gs 25 26

~/anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/_gsprint.py in 238 libgs = ctypes.util.find_library('gs') 239 if not libgs: --> 240 raise RuntimeError('Please make sure that Ghostscript is installed') 241 libgs = cdll.LoadLibrary(libgs) 242

RuntimeError: Please make sure that Ghostscript is installed

cwhan-yonsei avatar Jun 13 '19 07:06 cwhan-yonsei

macOS - brew install ghostscript - still get this error

jtlz2 avatar Jun 20 '19 08:06 jtlz2

Hi this error also exists for me.

lswh avatar Jun 20 '19 08:06 lswh

I was investigating this code earlier and I noticed for my macOS implementation that it's having some issue with the conditional of libgs.so file which produces the runtime error. I tried working on both virtualenv and conda but I also suspect that the find_library cdll is not working in it somewhere. It does not detect the GhostScript even when I installed from source and did a make so compiled install because that file extension for MacOS is a different one from shared object on Linux. I presume this bug does not happen on Ubuntu/Linux and can only be observed in Windows and MacOS. I will try on a Linux machine and see if I am able to detect the same bug.

lswh avatar Jun 20 '19 09:06 lswh

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

My code is now having no issues, too, thank you

This did the trick for me too.

nachiket8188 avatar Jun 26 '19 18:06 nachiket8188

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

I also tried, its working perfectly fine..just after installation

kavinsingh1 avatar Jul 30 '19 08:07 kavinsingh1

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues.

This worked for me too.

shivaniarbat avatar Aug 05 '19 18:08 shivaniarbat

Yes, on windows 10 it works after installing the ghostscript exe at: https://www.ghostscript.com/download/gsdnld.html

forum2k9 avatar Aug 13 '19 11:08 forum2k9

I had had this issue on aws elasticbeanstalk in a django app while reading a pdf : I just needed to add these lines packages: yum: ghostscript: [] in the django.configure file

sourabhsinha396 avatar Oct 07 '19 06:10 sourabhsinha396

Had the same Issue on Windows. I just installed Ghostscript installer from this Website: https://www.ghostscript.com/download/gsdnld.html My Code is now having no issues. I solved this problom by this url https://www.ghostscript.com/download/gsdnld.html

iicedream avatar Oct 18 '19 09:10 iicedream

Some hack:

Looking at sources: https://github.com/atlanhq/camelot/blob/9137df2f6c6acb2fdaef9256ac42bf11f6afd99e/camelot/ext/ghostscript/_gsprint.py#L223

My guess is that downloading : https://www.ghostscript.com/download/gsdnld.html install some HKEY_LOCAL_MACHINE aka GS_DLL which solved the problem.

For ones who cannot add HKEY_LOCAL_MACHINE, add it to HKEY_CURRENT_USER\Software\key_name\GS_DLL\GS_DLL GS_DLL is a REG_SZ containing dll path.

Choose key_name in "AFPL Ghostscript", "Aladdin Ghostscript", "GNU Ghostscript", "GPL Ghostscript",

Also import HKEY_CURRENT_USER here https://github.com/atlanhq/camelot/blob/9137df2f6c6acb2fdaef9256ac42bf11f6afd99e/camelot/ext/ghostscript/_gsprint.py#L192

and here:

https://github.com/atlanhq/camelot/blob/9137df2f6c6acb2fdaef9256ac42bf11f6afd99e/camelot/ext/ghostscript/_gsprint.py#L201

slamer59 avatar Nov 12 '19 15:11 slamer59

MacOS, had the same error after running brew install ghostscript

Running brew link --overwrite ghostscript solved it.

tsiq-maxime avatar Nov 12 '19 17:11 tsiq-maxime

"errorMessage": "Please make sure that Ghostscript is installed", "errorType": "RuntimeError"

getting this error while run the code using lambda function aws. Already camelot and ghostscript added as a dependency. I need to resolve as soon as possible. Please help.

my code is : import camelot

def pdfToJson(event=None,context=None): tables = camelot.read_pdf("./week-1-2019-20.pdf") tables[0].df.to_json("./sample.json")

Note:Locally it is working properly.

#serverless #awslambda #python #camelot #ghostscript

goutam-ghosh avatar Nov 15 '19 09:11 goutam-ghosh

And more thing how to add ghostscript dependencies for lambda function python?

goutam-ghosh avatar Nov 15 '19 11:11 goutam-ghosh

MacOS, had the same error after running brew install ghostscript

Running brew link --overwrite ghostscript solved it.

That also solved it for me (MacOS).

AJoR43 avatar Nov 20 '19 22:11 AJoR43

I tried all the solutions in this thread, conda, brew etc... Still doesn't work! I am on MacOS HighSierra version 10.13.6. Python 3.7.4

zeboventura avatar Nov 21 '19 15:11 zeboventura