Open rafiepstein opened 5 years ago
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)
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:
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.
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
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
Did the brew link --overwrite ghostscript
command execute without any errors?
@AJoR43 brew link --overwrite ghostscript
errored with:
Linking /usr/local/Cellar/ghostscript/9.50...
Error: Could not symlink share/doc/ghostscript/9.50
/usr/local/share/doc/ghostscript is not writable.
So then I tried running it with sudo, which is no longer allowed
Error: Running Homebrew as root is extremely dangerous and no longer supported.
Also tried installing directly from ghostcript.com and got other errors:
... long list
cp: /usr/local/share/ghostscript/9.50/#inst.35114#: No such file or directory
cp: /usr/local/share/ghostscript/9.50/#inst.35121#: No such file or directory
cp: /usr/local/share/ghostscript/9.50/#inst.35128#: No such file or directory
make: *** [install-libdata] Error 1
Resolved: deleted ghostcript folder /usr/local/share/doc/ghostscript
and ran brew link --overwrite ghostscript
again.
@vinayak-mehta Is there any update of this bug?
I hit the same error on a fresh conda environment with Python 3.7 on OSX with conda.
On my system, I managed to fix the issue by replacing https://github.com/atlanhq/camelot/blob/cd8ac7979fe3631866fe439f07e9d6aaa5b1e5c6/camelot/ext/ghostscript/_gsprint.py#L256 with
import distutils.spawn
libgs = distutils.spawn.find_executable("gs")
For some reason, ctypes.util.find_library
is not finding my installation of GS (installed via conda), but distutils.spawn.find_executable
manages to find the path to the executable, and passing this path to cdll.LoadLibrary
worked fine for me.
In my case, I don't have admin rights on the laptop I'm working. I installed ghostscript without admin in a user folder, then monkey patched the code to point directly to the library.
https://github.com/atlanhq/camelot/blob/master/camelot/ext/ghostscript/_gsprint.py
# libgs = __win32_finddll()
libgs = r'C:\Users\myusername\gs9.50\bin\gsdll64.dll'
Works like a charm! Now, it's not a generic solution. It would probably be best to search for the dll in the PATH rather than in the registry.
Even after trying everything on here, I've just gave up on the library. Shame, I was with really good expetations from it.
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.
For me too! Im using Windows :D thank you guys!
I encountered the same issue and can confirm that @fmassa solution worked for me, on OS X python 3.7 with conda installed ghostscript
"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 Did you get any solution? I am also facing exactly same issue.
Hi,
I am facing the same issue, in conda environment, Ghostscript and Camelot is installed from conda-forge for window10 environment. This ghostcript conda installation does not create the HKEY local machine registry. And Camelot Ghostscript is looking for the HKEY LOCAL MACHINE REGISTRY. I think this is a bug...to whom this should be addressed? CONDA , CAMELOT, PYTHON? ;)
have the save issue using environment:
camelot-py==0.7.3 chardet==3.0.4 click==7.1.1 et-xmlfile==1.0.1 ghostscript==0.6 jdcal==1.4.1 numpy==1.18.1 opencv-python==4.2.0.32 openpyxl==3.0.3 pandas==1.0.2 pdfminer==20191125 pdfminer.six==20200124 pycryptodome==3.9.7 PyPDF2==1.26.0 python-dateutil==2.8.1 pytz==2019.3 six==1.14.0 sortedcontainers==2.1.0
RuntimeError: Please make sure that Ghostscript is installed
I hit the same error on a fresh conda environment with Python 3.7 on OSX with conda.
On my system, I managed to fix the issue by replacing
with
import distutils.spawn libgs = distutils.spawn.find_executable("gs")
For some reason,
ctypes.util.find_library
is not finding my installation of GS (installed via conda), butdistutils.spawn.find_executable
manages to find the path to the executable, and passing this path tocdll.LoadLibrary
worked fine for me.
This worked for me!
I hit the same error on a fresh conda environment with Python 3.7 on OSX with conda.
On my system, I managed to fix the issue by replacing
with
import distutils.spawn libgs = distutils.spawn.find_executable("gs")
For some reason,
ctypes.util.find_library
is not finding my installation of GS (installed via conda), butdistutils.spawn.find_executable
manages to find the path to the executable, and passing this path tocdll.LoadLibrary
worked fine for me.
Also on fresh conda environment, 3.7, MacOS, and this also worked for me. Thank you!!
My issue was that I had a Python 32 bit on a 64 bit windows. I uninstalled an re-installed Python 64 bit and It started to work.
Thank you
Tamir
--
[image: Sisense] https://www.sisense.com/?source=xink&utm_source=xink&utm_medium=email&utm_campaign=emailsignature2018
Tamir Basin
Business Intelligence Consultant
+972-3-546-2266
tamir.sisense
[image: Instagram] https://www.instagram.com/sisense/
[image: LinkedIn] https://www.linkedin.com/company-beta/148828/?pathWildcard=148828
[image: Facebook] https://www.facebook.com/Sisense
[image: Twitter] https://twitter.com/Sisense
https://t.xink.io/Tracking/Index/Q8UBAPDBAAD-vVcA0
From: Charles Davis notifications@github.com Sent: Monday 13 April 2020 8:23 PM To: atlanhq/camelot camelot@noreply.github.com Cc: tamirbasin tamir.basin@sisense.com; Comment < comment@noreply.github.com> Subject: Re: [atlanhq/camelot] RuntimeError: Please make sure that Ghostscript is installed (#282)
I hit the same error on a fresh conda environment with Python 3.7 on OSX with conda.
On my system, I managed to fix the issue by replacing
with
import distutils.spawn
libgs = distutils.spawn.find_executable("gs")
For some reason, ctypes.util.find_library is not finding my installation of GS (installed via conda), but distutils.spawn.find_executable manages to find the path to the executable, and passing this path to cdll.LoadLibrary worked fine for me.
Also on fresh conda environment, 3.7, MacOS, and this also worked for me. Thank you!!
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/atlanhq/camelot/issues/282#issuecomment-612998714, or unsubscribe https://github.com/notifications/unsubscribe-auth/AO6EJZKTEZDRCWNBKANN3CDRMNC57ANCNFSM4GZ5HUWQ .
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 did the same thing but still the same error appears
I download the 64 for windows and it work fine now.
Hi, I had the same problem. It did some investigation and here are my observations for Window10 professional: -> Quick and clean solution - have all the stuff (python, ghostscript) installed as 64bit versions on 64 bit machine
If this is not an option, I don't know how to solve it, but I can give you some hints. The place of problem is here: Python38\Lib\site-packages\camelot\ext\ghostscript_gsprint.py.
Look at this code:
for key_name in (
"AFPL Ghostscript",
"Aladdin Ghostscript",
"GNU Ghostscript",
"GPL Ghostscript",
):
try:
k1 = OpenKey(HKEY_LOCAL_MACHINE, "Software\\%s" % key_name)
for num in range(0, QueryInfoKey(k1)[0]):
version = EnumKey(k1, num)
try:
In 32bit python, OpenKey does not see the key for GhostScript 64bits. The reason is displayed here - https://stackoverflow.com/questions/30932831/winreg-openkey-throws-filenotfound-error-for-existing-registry-keys. If you install the 32 bit GhostScript, then the keys are not in the registry. If you hardcode the path to a dll and run it, you will have memory violation. This where I have given up.
You might try installing 32 bit python, 64 bit GhostScript and use advice from https://stackoverflow.com/questions/30932831/winreg-openkey-throws-filenotfound-error-for-existing-registry-keys to have the code read the right registry keys. Maybe it will work. However, the code looks like calling a dll. So the situation would be that 32 bit python calls a 64 bit library. I am not saying it is not going to work. I am just pointing the difference.
So for me, it looks like the software was developed and tested on everything being 64 bits. It probably does not support a mixture of bitness.
I am using 64 bit Windows 10 machine.. For a version of python 64 bit ,and the gsdll64.dll (gs 64 bit) the Camelot is working fine ,but when we using a python 32 bit , In ,(_gsprint.py) file in the below line is not executing . is k1 = OpenKey(winreg.HKEY_LOCAL_MACHINE, "Software\%s" % key_name) Switch to a 64 bit version python solves my problem. Please give the solution for 32 bit version of Python.
I am experiencing the same issue when I am trying to use it on a binder that I use in one of my courses. I checked and ghostscript is installed.
So in principle it should be able to find it on the path. I installed GS via conda.
Strangely I do not have this issue on my Mac with the same environment, where I had GS installed via homebrew
.
tested using @fmassa's solution and the mybinder VM is able to find the library. I can't really change the line since I do not have editing access to that and would need to change the line every time I update. Nonetheless, running those lines provides the same libgs
object.
To see this, on my Mac I get
On Binder
I wonder if using that would solve it generally. Any reason it hasn't been suggested in a PR?
Hello, Trying to run a single line: (Python 2.7.15 under Pycharm)
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