camelot
camelot copied to clipboard
RuntimeError: Please make sure that Ghostscript is installed
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
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
Did you try the solutions mentioned in #184?
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?
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
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.
In macos brew install ghostscript
In my case, Ghostscript is successfully installed. Shouldn't this be a bug?
Ghostscript is successfully installed. Shouldn't this be a bug? yes it is a bug!!!!!
I'll look into this over the weekend.
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.
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.
Same issue here
Same for me. Even if i install ghostscript and python3-ghostscript via pip. macOS with PyCharm. Both latest versions.
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.
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
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
~/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)
~/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
~/anaconda3/lib/python3.7/site-packages/camelot/ext/ghostscript/_gsprint.py in
RuntimeError: Please make sure that Ghostscript is installed
macOS - brew install ghostscript
- still get this error
Hi this error also exists for me.
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.
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.
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
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.
Yes, on windows 10 it works after installing the ghostscript exe at: https://www.ghostscript.com/download/gsdnld.html
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
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
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
MacOS, had the same error after running brew install ghostscript
Running brew link --overwrite ghostscript
solved it.
"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
And more thing how to add ghostscript dependencies for lambda function python?
MacOS, had the same error after running
brew install ghostscript
Running
brew link --overwrite ghostscript
solved it.
That also solved it for me (MacOS).
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