我正在尝试创建条形图(使用Matplotlib)以保存在AWS S3存储桶中。它完全适用于我的笔记本电脑但是当我将代码上传到AWS Lambda(安装了正确的软件包)时,我收到了一个错误。这是代码:
import matplotlib.pyplot as plt
from boto3 import Session
import io
from datetime import date
months = [date(2018, month, 1).strftime('%b') for month in range(1, 13)]
filename = 'barplot.png'
BUCKET = 'my_bucket_name'
img_data = io.BytesIO()
counts = [
[606, 124, 759, 998, 234],
[762, 912, 639, 591, 135],
[492, 92, 119, 1131, 999],
]
plt.figure()
plt.title('Fantastic Title Goes Here')
plt.xlabel('Timeline')
plt.ylabel('base count')
x1 = [2.0, 4.0, 6.0, 8.0, 10.0]
x2 = [x - 0.5 for x in x1]
x3 = [x + 0.5 for x in x1]
plt.xticks(x1, months)
plt.bar(x3, counts[2], width=0.4, color="#ff0000", label="Bar 3 Label")
plt.bar(x2, counts[1], width=0.4, color="#87CEEB", label="Bar 2 Label")
plt.bar(x1, counts[0], width=0.4, color="#F4A460", label="Bar 1 Label")
plt.legend()
plt.axis([0.5, 25, 0, 1500])
# NOTE saving to a file: plt.savefig(filename)
plt.savefig(img_data, format='png')
img_data.seek(0)
s3 = Session().client('s3')
response = s3.put_object(Body=img_data, Bucket=BUCKET, ContentType='image/png',
Key=filename, ACL='public-read')
我收到以下错误: ImportError:无法导入名称'multiarray'
这是错误Traceback:
Traceback(most recent call last):
File "/var/task/support_functions/catch_exceptions.py", line 19, in wrapper
return function(*args, **kwargs)
File "/var/task/jokes/flow_jokes.py", line 13, in get_joke
import support_functions.charts
File "/var/task/support_functions/charts.py", line 1, in < module >
import matplotlib.pyplot as plt
File "/var/task/matplotlib/__init__.py", line 127, in < module >
from . import cbook
File "/var/task/matplotlib/cbook/__init__.py", line 35, in < module >
import numpy as np
File "/var/task/numpy/__init__.py", line 142, in < module >
from . import add_newdocs
File "/var/task/numpy/add_newdocs.py", line 13, in < module >
from numpy.lib import add_newdoc
File "/var/task/numpy/lib/__init__.py", line 8, in < module >
from .type_check import *
File "/var/task/numpy/lib/type_check.py", line 11, in < module >
import numpy.core.numeric as _nx
File "/var/task/numpy/core/__init__.py", line 26, in < module >
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean - xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name 'multiarray'
显然,我试图联合卸载并重新安装numpy和matplotlib几次并没有成功。
韩国社交协会