我做了一些必要的步骤,可以成功地从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?
可能是什么问题?
答案 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"