我可以在lambda代码中导入所需的python库。但是,我也想访问此库提供的CLI。 CLI由文件usr / bin / ocrmypdf启动,它实际上是一个shell脚本:
#!/usr/bin/env python3
import re
import sys
from ocrmypdf.__main__ import run
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(run())
我尝试将此文件添加到/ bin /文件夹的lambda层中。我收到此错误:
File "/opt/bin/ocrmypdf", line 4, in <module>
from ocrmypdf.__main__ import run
ModuleNotFoundError: No module named 'ocrmypdf'
我怀疑该脚本无法加载python。下面的处理程序代码将生成CLI的输出
import ocrmypdf # works properly
from ocrmypdf.__main__ import run
import logging
import os
print('Loading function')
def lambda_handler(event, context):
run() # this is called by the shell script, it works here
logging.info(os.system("ocrmypdf --help")) # error