Importing Python Module “Pulp” on Amazon AWS Lambd

2019-08-21 15:18发布

I have been trying to import python module "Pulp" to the Amazon AWS Lambda but getting an error. Pulp is an optimization module which can be installed using pip ("pip install pulp") but as in AWS Lambda I'm not sure how to install it so I zipped everything along with Lambda Function from my local machine and uploaded it to AWS Lambda.

The error which I received:-

"Attempted relative import in non-package: ValueError Traceback (most recent call last): File "/var/task/lambda_function.py", line 5, in lambda_handler import pulp File "/var/task/pulp.py", line 101, in from .constants import * ValueError: Attempted relative import in non-package"

Here is the link for .zip file https://drive.google.com/open?id=0B7SjHToKYgr3cXlHenpoOFljMDg

Thanks in advance.

2条回答
男人必须洒脱
2楼-- · 2019-08-21 15:58

The error is a standard Python error saying that it will only import things from the standard locations. Since that includes the current directory you should be good but your code includes

    from . import pulp

when you have pulp.py in your directory. If pulp.py was all that was needed you would be fine. But pulp.py wants to import .constants. That is a relative reference which would be fine since it is supposed to be in a module. In your case it is not fine. If you want to keep going on this path you will have to go through and remove these relative imports.

Also your .zip file includes .pyc files. Let these be generated on the target machine. Just send your .py's that they came from.

查看更多
\"骚年 ilove
3楼-- · 2019-08-21 16:10

Follow the instructions on http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html

On how to deploy to AWS lambda using virtualenv.

查看更多
登录 后发表回答