如何在 Google App Engine 中包含第三方 Python 库? [英] How to include third party Python libraries in Google App Engine?

查看:27
本文介绍了如何在 Google App Engine 中包含第三方 Python 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to add third party python libraries in Google App Engine, which are not provided by Google? I am trying to use BeautifulSoup in Google App Engine and unable to do so. But my question is for any library I want to use in Google App Engine.

推荐答案

实际上我认为 这个答案 更适合这里.

Actually I think this answer fits better here.

如果您想使用此列表中未包含的第 3 方库,则必须添加手动.

If you want to use 3rd party libraries that are not included in this list, then you'll have to add them manually.

为了手动包含任何其他库,您必须将它们放在 app.yaml 所在的目录中.例如,如果您具有以下结构:

In order to include manually any other library you have to have them inside the directory where the app.yaml lives. So for example if you have the following structure:

hello
├── libs
│   └── bs4 
├── hello.py 
└── app.yaml

然后在您的 hello.py 中,您必须将这两行放在文件的开头:

then in your hello.py you have to put these two lines in the beginning of the file:

import sys
sys.path.insert(0, 'libs')

这样做之后,您将能够使用要放入该 libs 目录中的任何 3rd 方库.

After doing that you'll be able to use any 3rd party library that you're going to put in that libs directory.

例如:

from bs4 import BeautifulSoup

这篇关于如何在 Google App Engine 中包含第三方 Python 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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