我想要的
我在Lambda上使用的python包(OCRMYPDF)需要轻子库liblept.so.5。在隔离导入代码时,我发现问题在于find_library('lept').打印结果不返回任何结果。
from ctypes.util import find_library
def lambda_handler(event, context):
liblept=find_library('lept')
print("liblept:%s"%liblept)我使用的python包需要许多本机编译的依赖项。我正在尝试使用lambda层导入这些。
层结构
/opt/
/opt/bin/
/opt/lib/
/opt/lib/liblept.so.5
/opt/tesseract我能够使用CDLL访问该文件(下面的代码)。但是我不想重写这个包,用CDLL替换每个find_library()。是否可以为find_library设置导入目录?
liblept=CDLL("/opt/lib/liblept.so.5") # found
print("liblept:%s"%liblept)我的图层代码可以工作
我用了一个码头图像来建立图层。依赖于轻子核的/opt/bin中的文件正在工作(tesseract运行正常,也测试了OCR )。
logging.info(os.system("tesseract --version"))输出
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发布于 2020-08-03 15:44:26
在Python上测试:3.7AWSlambda环境:
您需要将liblept.so (只需重命名liblept.so.5)添加到lambda包的/lib文件夹或层的/opt/lib中。该文件必须被称为liblept.so,因为find_library只查找".so"文件,而不是".so.5"文件:
来自python:https://docs.python.org/3/library/ctypes.html
ctypes.util.find_library(name)
Try to find a library and return a pathname. name is the library name without any prefix like lib, suffix like .so, .dylib or version number (this is the form used for the posix linker option -l). If no library can be found, returns None.当只添加"liblept.so"时,链接器会抱怨它找不到"liblept.so.5",所以我也将"liblept.so.5"添加到lib文件夹中。
也许其他人可以加入并找到一个不使用重复文件的解决方案。
available将自动使/opt/lib或/lib中的任何文件通过LD_LIBRARY_PATH可用。
在Python3.8上,您可能还需要包括ld和objdump,就像这个线程:https://forums.aws.amazon.com/thread.jspa?threadID=313506,虽然我还没有测试它。
https://stackoverflow.com/questions/59083051
复制相似问题