Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

python - Python3/cloud9/lambda - making imported modules available to lambda

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.

How do I get 3rd party modules installed so they work with both lambda local and lambda remote?

Code could not be simpler:

import sqlobject
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Answering my own question... These are instructions for Python 3.

First start with an empty environment, mine was called cycles.

Create a new lambda function:

enter image description here

Your folder structure now looks like this:

enter image description here

There will be two folders with the same name (a bit confusing - ask AWS not me).

Right button click on the top most folder with your lambda function name and select "Open terminal here". This gets you command line.

No need to use sudo, just install the packages you need. Install your packages into that folder:

python3 -m pip install --target=./ sqlobject

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=./

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 install sqlobject

You packages will be installed in the wrong place.

Your folder structure should look like this with the new added packeges installed: enter image description here

You can see the code to the right...it ran fine with the sqlobject package installed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...