问题
What I'm trying
A python package I'm using (OCRMYPDF) on Lambda needs the leptonica library liblept.so.5. On isolating the import code I found the issue is with find_library('lept'). Printing the result returns None.
from ctypes.util import find_library
def lambda_handler(event, context):
liblept=find_library('lept')
print("liblept:%s"%liblept)
The python package I'm using needs many native compiled dependencies. I'm trying to import these using lambda layers.
layer structure
/opt/
/opt/bin/
/opt/lib/
/opt/lib/liblept.so.5
/opt/tesseract
I'm able to access the file using CDLL (code below). But I don't want to rewrite the package and replace every find_library() with CDLL. Is it possible to set the import directory for find_library?
liblept=CDLL("/opt/lib/liblept.so.5") # found
print("liblept:%s"%liblept)
My layer code works
I used a docker image to build layer. The files in /opt/bin that depend on leptonica are working (tesseract runs properly, tested OCR as well).
logging.info(os.system("tesseract --version"))
output
START RequestId: d826d36c-4ce9-4b67-b501-8c9042edcf80 Version: $LATEST
tesseract 4.1.0
leptonica-1.78.0
libgif 5.1.4 : libjpeg 6b (libjpeg-turbo 1.2.90) : libpng 1.2.49 : libtiff 4.0.3 : zlib 1.2.8 : libwebp 0.3.0
Found AVX
Found SSE
END RequestId: d826d36c-4ce9-4b67-b501-8c9042edcf80
来源:https://stackoverflow.com/questions/59083051/how-to-use-ctypes-util-find-library-to-import-so-libraries-in-aws-lambda-pytho