bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml.
linux导入lxml包时,报错bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: lxml. Do you need to install a parser library?
from bs4 import BeautifulSoup
soup = BeautifulSoup('<p>Hello</p>', 'lxml')
print(soup.p.string)
Traceback (most recent call last):
File "C:\Users\Lenovo\Desktop\Spider_1.py", line 6, in <module>
soup = BeautifulSoup(req.content,"lxml")
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python35\lib\site-packages\bs4\__init__.py", line 165, 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?
这里需要注意的是在使用 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
至此,问题完美解决,若不能解决,请评论留言私信给我,希望能帮到大家。
还没有评论,来说两句吧...