【发布时间】:2022-09-28 01:25:51
【问题描述】:
您好,我在尝试使用 tabula 读取 pdf 中的表格时收到以下错误。
我意识到将这个包与 AWS lambda 一起使用会遇到一些困难(here),并尝试通过 EC2(Ubuntu 20.02)压缩 tabula 包,然后将其作为层添加到函数中。
提前谢谢了!
{ \"errorMessage\": \"`java` command is not found from this Python process.Please ensure Java is installed and PATH is set for `java`\", \"errorType\": \"JavaNotFoundError\", \"stackTrace\": [ \" File \\\"/var/task/lambda_function.py\\\", line 39, in lambda_handler\\n df = tabula.read_pdf(BytesIO(fs), pages=\\\"all\\\", area = [box],\\n\", \" File \\\"/opt/python/lib/python3.8/site-packages/tabula/io.py\\\", line 420, in read_pdf\\n output = _run(java_options, tabula_options, path, encoding)\\n\", \" File \\\"/opt/python/lib/python3.8/site-packages/tabula/io.py\\\", line 98, in _run\\n raise JavaNotFoundError(JAVA_NOT_FOUND_ERROR)\\n\" ] }
代码
import boto3
import read_pdf from tabula
from io import BytesIO
def lambda_handler(event, context):
client = boto3.client(\'s3\')
s3 = boto3.resource(\'s3\')
# Get most recent file name
response = client.list_objects_v2(Bucket=\'S3bucket\')
all = response[\'Contents\']
latest = max(all, key=lambda x: x[\'LastModified\'])
latest_key = latest[\'Key\']
# Get file
obj = s3.Object(\'S3bucket\', latest_key)
fs = obj.get()[\'Body\'].read()
# Read PDF
box = [3.99, .22, 8.3, 7.86]
fc = 72
for i in range(0, len(box)):
box[i] *= fc
df = tabula.read_pdf(BytesIO(fs), pages=\"all\", area = [box], output_format = \"dataframe\", lattice=True)
标签: python aws-lambda tabula-py