无法将cvxpy安装到适用于AWS Lambda的virtualenv中 [英] Unable to install cvxpy into virtualenv for AWS lambda
问题描述
我正在尝试在AWS Lambda函数中运行cvxpy软件包。该软件包不在SDK中,因此,我读到必须将依赖项编译为zip,然后将zip上传到lambda函数中。
我已经做了一些研究,并尝试了下面的链接,但是当我尝试点安装cvxpy时,我收到错误消息-我在Windows机器上,但是我知道AWS Lambda在Linux上运行。
感谢帮助!
Lambda函数执行:
I am trying to run the cvxpy package in an AWS lambda function. This package isn't in the SDK, so I've read that I'll have to compile the dependencies into a zip, and then upload the zip into the lambda function.
I've done some research and tried out the links below, but when I try to pip install cvxpy I get error messages - I'm on a Windows box, but I know that AWS Lambda runs on Linux.
Appreciate the help!
https://programwithus.com/learn-to-code/Pip-and-virtualenv-on-Windows/
https://www.cvxpy.org/install/index.html
For installing cvxpy
on windows it requires c++ build tools (please refer: https://buildmedia.readthedocs.org/media/pdf/cvxpy/latest/cvxpy.pdf)
On Windows:
- I created a lambda layer python directory structure
python/lib/python3.7/site-packages
(refer: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) and installed my pip packages in that site-packages directory.
pip install cvxpy --target python/lib/python3.7/site-packages
- Then, I zipped the
python/lib/python3.7/site-packages
as cvxpy_layer.zip and uploaded it to an S3 bucket (layer zipped file max limit is only 50 MB https://docs.aws.amazon.com/lambda/latest/dg/limits.html), to attach it to my lambda layers. - Now, the layer is ready but the lambda is failing to import the packages as they were installed on a windows machine. (refer: AWS Lambda - unable to import module 'lambda_function')
On Linux:
- I created the same directory structure as earlier
python/lib/python3.7/site-packages
and installed the cvxpy and zipped it as shown below. - Later I uploaded the zip file to an S3 bucket and created a new lambda layer.
- Attaching that lambda layer to my lambda function, I colud able to resolve the import issues failing earlier and run the basic cvxpy program on lambda.
mkdir -p alley/python/lib/python3.7/site-packages
pip install cvxpy --target alley/python/lib/python3.7/site-packages
cd alley
zip -rqvT cvxpy_layer.zip .
Lambda layer Image:
Lambda function execution:
这篇关于无法将cvxpy安装到适用于AWS Lambda的virtualenv中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!