上传Python第三方库 [英] Uploading Python third party libraries
问题描述
Google App引擎文档指出,只要用纯Python编写,就可以上传和使用第三方库。
我需要执行哪些步骤这样做吗?
我所做的是在我的根目录下创建一个名为fix_path.py的文件, p>
导入os
导入sys
导入jinja2
#lib路径到lib direcotory
sys .path.insert(0,os.path.join(os.path.dirname(__ file__),'lib'))
然后我创建了一个lib目录,并将模块放在那里。
例如,我使用WTForms。我的文件结构如下所示。
- lib
- wtforms
- fix_path.py
- somefile.py
当我准备从我的somefile脚本中调用它时
import fix_path#必须是第一。
import wtforms
这里是我的github源代码中的这个例子。 checkout fix_path.py用于设置和views.py用法。
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?
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'))
Then I created a lib directory, and drop the module in there.
For example, I use WTForms. My file structure looks like this.
- lib
- wtforms
- fix_path.py
- somefile.py
when I am ready to call it from my somefile script
import fix_path # has to be first.
import wtforms
here is this example in my github source. checkout fix_path.py for setup and views.py for usage.
这篇关于上传Python第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!