python - 如何在 Google App Engine 中包含第三方 Python 库?

标签 python google-app-engine

如何在 Google App Engine 中添加非 Google 提供的第三方 Python 库?我正在尝试在 Google App Engine 中使用 BeautifulSoup,但无法这样做。但我的问题是针对我想在 Google App Engine 中使用的任何库。

最佳答案

Google 为您的 GAE 项目中包含的第三方库提供了文档化方式。

"Adding Third-party Packages to the Application" section of the Libraries in Python 2.7 docs .

If you want to include additional pure-python third-party packages, you can do so by setting up vendoring. Vendoring allows you to install packages to a subdirectory of your project and include them in your code. To use vendoring, create (or modify) appengine_config.py in the root of your project.

from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('lib')

然后将所有库的源代码放入 lib 目录

> pip install beautifulsoup4 -t lib

所以你的项目目录结构是这样的:

project
- lib
  - bs4
- your_code.py

这将允许您的项目的源文件导入库的包/模块,就像它们已添加到您的 PYTHON_PATH 一样。例如:

# file: your_code.py
import bs4  # no need for 'from lib import bs4'
# do stuff with bs4...

您还可以通过执行以下命令轻松安装 requirements.txt 文件中的所有内容

> pip install -t lib -r requirements.txt

关于python - 如何在 Google App Engine 中包含第三方 Python 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14850853/

相关文章:

python - 蓝牙 - 即使在 Python 的 Linux 设备中也能听配对

python - python 2.7 中没有名为 antlr4 的模块

java - 如何取消或停止 Google App Engine Cron Job

java - 将 java 对象序列化为 objective-c plist

python - Tipfy session 管理

python - 如何打印没有索引的 Pandas 数据框

python - Pandas 基于另一列添加新列

python - 用 Python 制作实时图表的好框架?

python - 如何在 Python 中对 Google App Engine 上的 utf-8 字符串进行排序?

google-app-engine - Google App Engine 是否支持 C++?