上传 Python 第三方库 [英] Uploading Python third party libraries

查看:49
本文介绍了上传 Python 第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google App 引擎文档声明可以上传和使用第三方库,前提是它们是用纯 Python 编写的.

Google App engine documentation states that it is possible to upload and use third party libraries provided they written in pure Python.

为此我需要采取哪些步骤?

What are the steps I need to take to do this?

推荐答案

我所做的是在我的根目录中创建了一个名为 fix_path.py 的文件,如下所示:

What I did is created a file called fix_path.py in my root directory that looks like this:

import os
import sys
import jinja2   
# path to lib direcotory
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))

然后我创建了一个 lib 目录,并将模块放在那里.

Then I created a lib directory, and drop the module in there.

例如,我使用 WTForms.我的文件结构是这样的.

For example, I use WTForms. My file structure looks like this.

    • wtforms

    当我准备好从我的 somefile 脚本调用它时

    when I am ready to call it from my somefile script

    import fix_path # has to be first.
    import wtforms
    

    这里是我 github 源中的这个示例.结帐 fix_path.py 用于设置和 views.py 用于使用.

    here is this example in my github source. checkout fix_path.py for setup and views.py for usage.

    这篇关于上传 Python 第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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