bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml.

迈不过友情╰ 2022-02-19 06:17 217阅读 0赞

linux导入lxml包时,报错bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: lxml. Do you need to install a parser library?

  1. from bs4 import BeautifulSoup
  2. soup = BeautifulSoup('<p>Hello</p>', 'lxml')
  3. print(soup.p.string)
  4. Traceback (most recent call last):
  5. File "C:\Users\Lenovo\Desktop\Spider_1.py", line 6, in <module>
  6. soup = BeautifulSoup(req.content,"lxml")
  7. File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python35\lib\site-packages\bs4\__init__.py", line 165, in __init__
  8. % ",".join(features))
  9. bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

这里需要注意的是在使用 pip install lxml时,自动安装的 4.1.1版本,

下载lxml 3.7.3安装后,问题则可解决:

pip install lxml==3.7.3(Python2)

pip install lxml==3.7.3(Python3)

若还是报错,问题仍然存在,则有可能是lxml包依赖的其他包没有安装,需要先安装其他包然后再安装lxml

安装python-pip:方便安装python的第三方包

[root@******/]# wget https://bootstrap.pypa.io/get-pip.py —no-check-cert

[root@******/]# python get-pip.py

ubuntu 下安装lxml:

安装依赖包 :[root@******/]# apt-get install libxml2-dev libxslt-dev python-dev

然后安装lxml:[root@******/]# apt-get install python-lxml

centos 下安装lxml:

安装依赖包 :[root@****** /]# yum install libxslt-devel python-devel
然后安装lxml:[root@****** /]# pip install lxml==3.7.3

至此,问题完美解决,若不能解决,请评论留言私信给我,希望能帮到大家。

发表评论

表情:
评论列表 (有 0 条评论,217人围观)

还没有评论,来说两句吧...

相关阅读