beautifulsoup不会识别lxml

rob*_*228 13 python lxml beautifulsoup

我正在尝试使用lxmlBeautifulSoup的解析器,因为默认值较慢,但是我收到此错误:

    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?
Run Code Online (Sandbox Code Playgroud)

我已经卸载并重新安装了lxml以及beautifulsoup多次,但它仍然无法读取它.我也尝试重新安装lxml依赖项,我仍然得到这个.

我甚至创建了一个新的虚拟环境并安装了新的一切,但仍然出现此错误.

任何人都知道这里发生了什么?

编辑

在ubuntu桌面上使用Python 2.7.x上的最新版本的bs4和lxml

我可以,import lxml但我不能from 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)
Run Code Online (Sandbox Code Playgroud)

我有libxml但是我不确定版本,但我安装并重新安装了最新版本.还尝试手动安装2.9.0仍然没有

unu*_*tbu 7

看起来lxml尚未成功安装.要lxml在Ubuntu上安装,请运行

sudo apt-get install libxslt1-dev libxml2
Run Code Online (Sandbox Code Playgroud)

在virtualenv:

pip install --upgrade lxml
pip install cssselect
Run Code Online (Sandbox Code Playgroud)