在Google App Engine中安装常用库 [英] Installing usual libraries inside Google App Engine

查看:84
本文介绍了在Google App Engine中安装常用库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何在Google App Engine中安装(或者应该在哪里放置和组织)通常的Python库。

有些库需要使用setuptools进行安装。如何安装这些库。

解决方案

您需要将库解包到应用程序的子目录中,然后添加库目录到请求处理程序模块中的Python路径。安装脚本需要的任何步骤,您必须手动执行,但通常没有任何操作,除非库捆绑了一个本地模块(无论如何,App Engine都不支持)。



如果您的库包含许多文件,可以压缩它们并使用zipimport,但这有点复杂,并且会影响性​​能。

例如,

例如,假设你将一个库放在lib / mylibrary中,位于你应用程序的目录下。在您的请求处理程序模块中,在任何其他导入之前添加以下内容:

  import os 
import sys
sys.path.append(os.path.join(os.path.dirname(__ file__),lib / mylibrary))

(请注意,这假设您的请求处理程序位于您的应用程序的根目录中。)


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.

解决方案

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

这篇关于在Google App Engine中安装常用库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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