我正在嘗試使用Python創建AWS lambda函數。而不是內聯函數,我想創建一個zip部署包,然後將其上載到我的AWS環境中。我有我的源代碼在test.py文件和其他依賴關係,如numpy,sklearn等在與我的源代碼是相同的文件夾中。AWS lambda構建python中的外部依賴庫
我在測試我的lambda函數時遇到錯誤。
無法導入模塊 '測試':無模塊名爲 'sklearn .__ check_build._check_build' ___________________________________________________________________________的/ var /任務的內容/ sklearn/__ check_build:setup.py
__pycache__ _check_build.cp36,win_amd64 .pyd __init__.py ___________________________________________________________________________似乎scikit-learn沒有被正確構建。如果你有從源安裝的scikit- ,請不要忘記在使用它之前建立 包:運行python setup.py install
或make
在 的源目錄中。如果您使用的是安裝程序,請檢查它是否適合您的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的我的Python源代碼。 (不能導入多陣列)
我正在使用pip install numpy/scikit-learn -t /path/to/mydir/
安裝每個庫。
Here is the folder structure after I use pip install commands
請幫我解決這個問題。謝謝 !!
[使用Scikit學習AWS Lambda](https://serverlesscode.com/post/deploy-scikitlearn-on-lamba) – darthsidious