Please make sure that Ghostscript is installed in Lambda
goutam-ghosh opened this issue · 18 comments
Hi,
I am using ARN what you provided.
arn:aws:lambda:ap-south-1:764866452798:layer:ghostscript:1
But still giving the error below in lambda
"errorMessage": "Please make sure that Ghostscript is installed".
Please help me.
Hello, @goutam-ghosh I will try to help you. Can you confirm that you are executing your Ghostscript command from the path /opt/bin/gs?
@goutam-ghosh Which version of Python do you use?
@goutam-ghosh Can you please provide the code sample you are trying to run? I need more information on that to help you solve an issue
@KnupMan
I am using camelot library. So camelot library depends on ghostscript.
sample code below:
import camelot
import subprocess, os
os.environ["PATH"] = os.environ["PATH"] + ":/opt/bin/gs"
print (os.environ["PATH"])
tables = camelot.read_pdf("./example.pdf")
tables[0].df.to_json("./sample1.json")@goutam-ghosh did you try instead of os.environ["PATH"] = os.environ["PATH"] + ":/opt/bin/gs" writing os.environ["PATH"] = os.environ["PATH"] + ":/opt/bin" ?
@vladgolubev
given same error
Modified code below
import camelot
import subprocess, os
os.environ["PATH"] = os.environ["PATH"] + ":/opt/bin"
print (os.environ["PATH"])
tables = camelot.read_pdf("./example.pdf")
tables[0].df.to_json("./sample1.json")
@goutam-ghosh please open issue in the camelot repository, this has nothing to do with the Lambda layer. This layer just simply provides a compiled library, it's not responsible for other libraries and the way they decide to load ghostscript
@vladgolubev This is problem in lambda ghostscript layer. Because I have already check it locally. It is working fine locally.
In local I have installed the ghostscript.
@goutam-ghosh the only job of this layer is to provide a Ghostscript binary which it does
I'm not familiar with Python, maybe there is a specific way how do you tell Python to find that binary in a non-default path
You could try running smth like this inside Lambda to see that the binary is really there and it's working
import subprocess
subprocess.run(["/opt/bin/gs", "--version"])@vladgolubev
giving below response
Response:
null
Request ID:
"7a3f4e23-6f5f-4747-a580-67583b09929c"
Function Logs:
START RequestId: 7a3f4e23-6f5f-4747-a580-67583b09929c Version: $LATEST
END RequestId: 7a3f4e23-6f5f-4747-a580-67583b09929c
REPORT RequestId: 7a3f4e23-6f5f-4747-a580-67583b09929c Duration: 92.31 ms Billed Duration: 100 ms Memory Size: 1216 MB Max Memory Used: 70 MB Init Duration: 1.45 ms
@goutam-ghosh could you please log the subprocess.run(["/opt/bin/gs", "--version"]) response?
@vladgolubev It is given null response.
@goutam-ghosh could you please print what subprocess.run function returns?
@vladgolubev
Giving below output
CompletedProcess(args=['/opt/bin/gs', '--version'], returncode=0, stdout=b'9.20\n')
@goutam-ghosh stdout=b'9.20\n' shows that there is Ghostscript version 9.20 installed in your Lambda! So the problem is not with this layer, but rather with the camelot library or your code, which doesn't see Ghostscript installed in a non-standard path.
Firstly, thanks for hosting the layer - it worked like a charm. It would be much helpful if the **libgs.so.*9.5 are also made available in a /lib64 folder. The reason for the above error is also the same, that the camelot library is trying to find libgs.so.9.52 but couldn't find it.
An easy replication of the above error is as follows..
# Any one of the below sections of code should have a value
# sec: 1
from ctypes import *
cdll = LibraryLoader(CDLL)
libgs = cdll.LoadLibrary("libgs.so") # or "/opt/lib64/libgs.so"
print("libgs should not be null -->", libgs)
#sec 2
import ctypes.util
libgs = ctypes.util.find_library("gs")
print("libgs should not be null -->", libgs)