Python3/cloud9/lambda-使导入的模块可用于lambda [英] Python3/cloud9/lambda - making imported modules available to lambda
问题描述
使用sqlobject.导入模块时,在本地或远程运行lambda时出现无法加载模块的错误.该模块已安装,如果我获得了命令行python3解释器并导入了模块,则可以正常导入.
Using sqlobject. When I import the module I get a unable to load module error when running lambda local or remote. The module is installed and if I get a command line python3 interpreter and import the module it imports just fine.
我如何安装第3方模块,以便它们与lambda local和lambda remote一起使用?
How do I get 3rd party modules installed so they work with both lambda local and lambda remote?
代码再简单不过了:
import sqlobject
推荐答案
回答我自己的问题... 这些是Python 3的说明.
Answering my own question... These are instructions for Python 3.
首先从一个空的环境开始,我的被称为循环.
First start with an empty environment, mine was called cycles.
创建一个新的lambda函数:
Create a new lambda function:
您的文件夹结构现在看起来像这样:
Your folder structure now looks like this:
会有两个具有相同名称的文件夹(有点令人困惑-问AWS不是我).
There will be two folders with the same name (a bit confusing - ask AWS not me).
右键单击带有lambda函数名称的最上面的文件夹,然后选择在此处打开终端".这将为您提供命令行.
Right button click on the top most folder with your lambda function name and select "Open terminal here". This gets you command line.
无需使用sudo,只需安装所需的软件包即可.将软件包安装到该文件夹中:
No need to use sudo, just install the packages you need. Install your packages into that folder:
python3 -m pip install --target =./sqlobject
python3 -m pip install --target=./ sqlobject
重要 您需要将软件包安装在打开终端的顶部文件夹中.请参见pip安装行中的部分内容:
IMPORTANT You need to install the packages in that top folder that you opens a terminal from. See the part of the pip install line that says:
-target =./
--target=./
可确保将软件包安装在lambda可以使用的正确文件夹中.如果您使用标准的pip安装:
that makes sure the packages get installed in the right folder that lambda can use. If you use the standard pip install:
python3 -m pip安装sqlobject
python3 -m pip install sqlobject
您的软件包将安装在错误的位置.
You packages will be installed in the wrong place.
您的文件夹结构应如下所示,其中安装了新添加的软件包:
Your folder structure should look like this with the new added packeges installed:
您可以在右侧看到代码...安装了sqlobject软件包后,它运行良好.
You can see the code to the right...it ran fine with the sqlobject package installed.
这篇关于Python3/cloud9/lambda-使导入的模块可用于lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!