如何通过dev_appserver.py在Google App Engine上将BeautifulSoup与lxml一起使用

时间:2018-10-22 19:45:19

标签: python google-app-engine beautifulsoup lxml dev-appserver

我做了一些必要的步骤,可以成功地从shell运行:

pip install lxml -t lib
cd lib
python
>>> from bs4 import BeautifulSoup
>>> import lxml
>>> res = BeautifulSoup("<p>hello</p>","lxml")
>>> print res
<html><body><p>hello</p></body></html>

但是在带有dev_appserver.py的Google App Engine上没有成功:

 from bs4 import BeautifulSoup
 import lxml
 import lxml
 p1 = BeautifulSoup("<p>toto</p>","lxml")

错误是:

Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

可能是什么问题?

1 个答案:

答案 0 :(得分:2)

lxml库是Python 2.7运行时的built-in third-party library库,但是默认情况下dev_appserver.py不附带。您需要将其单独安装在计算机上:

pip install lxml==2.3.5

请参阅this guide的“将内置的捆绑库与本地开发服务器一起使用”一节。

部署时,您需要将其添加到app.yaml

libraries:
- name: lxml
  version: "2.3.5"