【发布时间】:2017-12-24 01:40:13
【问题描述】:
我正在尝试使用 Python 创建一个 AWS lambda 函数。我想要创建一个 zip 部署包,然后将其上传到我的 AWS 环境中,而不是内联函数。我的源代码位于 test.py 文件中,其他依赖项(如 numpy、sklearn 等)与我的源代码位于同一文件夹中。
我在测试 lambda 函数时遇到错误。
无法导入模块“test”:没有命名模块 'sklearn.__check_build._check_build' ___________________________________________________________________________ /var/task/sklearn/__check_build 的内容:setup.py
__pycache__ _check_build.cp36-win_amd64.pyd __init__.py ___________________________________________________________________________ scikit-learn 似乎没有正确构建。如果你有 从源代码安装 scikit-learn,请不要忘记构建 使用前打包:运行python setup.py install或makein 源目录。如果您使用了安装程序,请检查 它适用于您的 Python 版本、操作系统和您的 平台。
这是我的 python 源代码,它位于 test.py 中
from sklearn.model_selection import train_test_split
print('Loading function')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
print("value1 is " + event['key1'])
print("value2 is " + event['key2'])
print("value3 is " + event['key3'])
return event
如果我在源代码中导入 numpy,我将面临类似的问题。 (无法导入多数组)
我正在使用pip install numpy/scikit-learn -t /path/to/mydir/ 安装每个库。
Here is the folder structure after I use pip install commands
请帮我解决问题。谢谢!!
【问题讨论】:
标签: python amazon-web-services numpy lambda scikit-learn