尝试将 xlsx 文件保存到 S3 存储桶时出错

时间:2021-01-27 00:19:45

标签: python-3.x pandas amazon-web-services amazon-s3 xlsxwriter

尝试使用以下方法将 xlsx 文件保存到 s3 存储桶:

import io
import pronounceable
import boto3
import xlsxwriter
import pandas as pd

bucket = 'your-s3-bucketname'
filepath = 'path/to/your/file.format'
df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]})

with io.BytesIO() as output:
    with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
        df.to_excel(writer, 'sheet_name')
    data = output.getvalue()
s3 = boto3.resource('s3')
s3.Bucket(bucket).put_object(Key=filepath, Body=data)

然而,这会导致以下错误:

No module named 'xlsxwriter': ModuleNotFoundError

我尝试将 xlsxwriter 作为层安装到我的 lamdbda 函数中(就像我安装其他包/模块一样),但似乎我已经在使用分配的层文件空间量。

Layers consume more than the available size of 262144000 bytes

问题

无论如何,我是否可以在没有 xlsxwriter 的情况下导出文件,或者以其他方式增加为图层分配的空间以便我可以添加它?

0 个答案:

没有答案