views:

171

answers:

2

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.

+3  A: 

Most of them can be installed using the pip.

Follow 3 first points from the Google wiki.

tkopczuk
+2  A: 

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.)

Nick Johnson
Could you give a simple example (or link)? How and where (main.py?) should I modify PYTHONPATH? Should I use os.environ for setting PYTHONPATH? Thank you.
Oleksandr Bolotov
Does this help? :)
Nick Johnson