我正在尝试使用lxml作为BeautifulSoup的解析器,因为默认值较慢,但是我收到此错误:
soup = BeautifulSoup(html, "lxml")
File "/home/rob/python/stock/local/lib/python2.7/site-packages/bs4/__init__.py", line 152, in __init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
我已经卸载并重新安装了lxml以及beautifulsoup多次,但它仍然无法读取它.我也尝试重新安装lxml依赖项,我仍然得到这个.
我甚至创建了一个新的虚拟环境并安装了新的一切,但仍然出现此错误.
任何人都知道这里发生了什么?
编辑
在ubuntu桌面上使用Python 2.7.x上的最新版本的bs4和lxml
我可以导入lxml但我不能从lxml import etree返回:
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/x86_64-linux-gnu/libxml2.so.2: version `LIBXML2_2.9.0' not found (required by /home/rob/python/stock/local/lib/python2.7/site-packages/lxml/etree.so)
我有libxml但是我不确定版本,但我安装并重新安装了最新版本.还尝试手动安装2.9.0仍然没有
解决方法:
看起来lxml尚未成功安装.要在Ubuntu上安装lxml,请运行
sudo apt-get install libxslt1-dev libxml2
在virtualenv:
pip install --upgrade lxml
pip install cssselect