Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

python 3.x - Error when attempting to save xlsx file to S3 bucket

Attempting to save an xlsx file to an s3 bucket using the following method:

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)

However this results in the following error:

No module named 'xlsxwriter': ModuleNotFoundError

I have tried to install xlsxwriter as a layer to my lamdbda function (as I have with other packages/modules) but it seems I am already using the allocated amount of file space for layers.

Layers consume more than the available size of 262144000 bytes

QUESTION

Is there anyway I export the file without xlsxwriter or otherwise increase the allocated space for layers so that I can add it?

question from:https://stackoverflow.com/questions/65911211/error-when-attempting-to-save-xlsx-file-to-s3-bucket

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...