获取PIL/Pillow 4.2.1正确上载到AWS Lambda Py3.6 [英] Getting PIL/Pillow 4.2.1 to upload properly to AWS Lambda Py3.6

查看:162
本文介绍了获取PIL/Pillow 4.2.1正确上载到AWS Lambda Py3.6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

过去几天,我一直在努力部署使用Pillow的Lambda,并且正在使用Python 3.6进行部署.同样值得注意的是,我正在Windows 10环境中进行开发.

首次尝试

我首先通过执行以下操作让pip严格在我的工作区中安装软件包:

pip3 install pillow -t "D:\Work and Projects\...\...\<projectdir>\pillow"

我还有其他软件包,并尝试在同一庄园中安装这些软件包,其中一个具体是praw,我这样做是:

pip3 install praw -t "D:\Work and Projects\...\...\<projectdir>\praw"

将项目内容压缩在一起之后,我将程序包上传到Lambda,并且在我的第一次测试中收到错误消息:

无法导入模块'motw_lambda':无法导入名称'_imaging'

然后,我删除了Pillow软件包,以查看此问题的根源(Pillow或praw或其他软件包之一).删除枕头后,执行成功.然后,我删除了我包中的pillow包并尝试:

pip3 install pillow -t "D:\Work and Projects\...\...\<projectdir>\PIL"

pip3 install pillow -t "D:\Work and Projects\...\...\<projectdir>\Pillow"

但是软件包'_imaging'遇到了相同的错误.

更多尝试

然后,我按照此资源.我还尝试使用 virualenv 甚至是解决方案

基本上,您必须使用Docker甚至是更好的EC2实例来编译库(例如PIL).

  1. 像这样启动Docker容器:docker run --rm -it -v "%cd%:/code" lambci/lambda:build-python3.6 sh

  2. 在其中,导航到/code目录(cd /code),创建一个virtualenv(virtualenv env),将其激活(source env/bin/activate),最后,安装您的库(pip install pillow). /p>

  3. 一旦安装了库,就可以退出容器.这里的秘密是将包库移动到根文件夹(主.py文件所在的位置).例如,将文件夹env/lib/python3.6/site-packages/PIL移至根目录.

然后,将您的PIL文件夹与.py文件一起压缩,就可以设置好了!

我只是这样做并在此处完整记录了它: https://Learn-serverless.org/post/deploying-pillow-aws-lambda/

Background

I have been struggling for the past few days to deploy a Lambda that uses Pillow, and I am deploying using Python 3.6. It may be noteworthy also that I am developing this on a Windows 10 environment.

First Attempts

I began by having pip install my packages strictly in my workspace by doing the following:

pip3 install pillow -t "D:\Work and Projects\...\...\<projectdir>\pillow"

I have other packages, and tried installing the packages in the same manor, one of them specifically was praw and I did so by:

pip3 install praw -t "D:\Work and Projects\...\...\<projectdir>\praw"

After zipping the contents of my project together, I uploaded my package up to Lambda and upon my first test I received the error:

Unable to import module 'motw_lambda': cannot import name '_imaging'

I then removed the Pillow package in an attempt to see where this issue was stemming from (Pillow or praw or one of the other packages). With Pillow removed, the execution succeeded. I then removed the pillow package in my package and tried:

pip3 install pillow -t "D:\Work and Projects\...\...\<projectdir>\PIL"

and

pip3 install pillow -t "D:\Work and Projects\...\...\<projectdir>\Pillow"

But got the same error with the package '_imaging'.

Further Attempts

I then followed the directions per this resource and this. I also tried using virualenv and even lambda-uploader.

Strange enough, I get the same error! I am all out of options here, and feel either I am doing something dumb, or that this is not possible on Lambda-Python3.6 currently (Although I can't image someone else hasn't used pillow in a py3.6-lambda yet...)

Any info, help, or generic resources would be appreciated!

解决方案

Basically, you have to compile the libraries (eg, PIL) either using Docker or, even better, an EC2 instance.

  1. Launch an Docker container like this: docker run --rm -it -v "%cd%:/code" lambci/lambda:build-python3.6 sh

  2. Inside there, navigate to the /code dir (cd /code), create a virtualenv (virtualenv env), activate it (source env/bin/activate) and finally, install your library (pip install pillow).

  3. Once you have installed your library, you can exit the container. The secret here is to move your package library to the root folder (where your main .py file is). For example, move the folder env/lib/python3.6/site-packages/PIL to the root.

Then, zip your PIL folder together with your .py file and you're set!

I just did it and documented it in full here: https://learn-serverless.org/post/deploying-pillow-aws-lambda/

这篇关于获取PIL/Pillow 4.2.1正确上载到AWS Lambda Py3.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆