Installing usual libraries inside Google App Engin

2019-05-24 08:57发布

How should I install (or where should I put and organize) usual python libraries in Google App Engine.

Some libraries require to be installed using setuptools. How can I install that libraries.

2条回答
三岁会撩人
2楼-- · 2019-05-24 09:19

Most of them can be installed using the pip.

Follow 3 first points from the Google wiki.

查看更多
爷、活的狠高调
3楼-- · 2019-05-24 09:26

You need to unpack the libraries into a subdirectory of your app, and add the library directory to the Python path in your request handler module. Any steps required by setup scripts, you'll have to execute manually, but there generally aren't any unless the library bundles a native module (which aren't supported on App Engine anyway).

If your library contains many files, it's possible to zip them and use zipimport, but that's somewhat more complex, and has performance implications.

For example, suppose you put a library in lib/mylibrary, under your app's directory. In your request handler module, add the following before any of your other imports:

import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "lib/mylibrary"))

(Note that this assumes that your request handler is in the root directory of your app.)

查看更多
登录 后发表回答