python lxml库不能识别,beautifulsoup无法识别lxml

I'm attempting to use lxml as the parser for BeautifulSoup because the default one is MUCH slower, however i'm getting this error:

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?

I have uninstalled and reinstalled lxml as well as beautifulsoup many times, however it still will not read it. I've tried reinstalled lxml dependencies as well and i'm still getting this.

I even made a new virtual environment and installed fresh everything and still get this error.

Anyone have any idea whats going on here?

Edits

Using latest versions of bs4 and lxml on Python 2.7.x on ubuntu desktop

i can import lxml but i cannot from lxml import etree that is returning:

File "", line 1, in

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)

i have libxml however i'm not sure the version, but i installed and reinstalled the latest. also tried to manually install 2.9.0 and still nothing

解决方案

It looks like lxml has not been successfully installed. To install lxml on Ubuntu, run

sudo apt-get install libxslt1-dev libxml2

In virtualenv:

pip install --upgrade lxml

pip install cssselect

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值