Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

python - BeautifulSoup - "Couldn't find a tree builder" error, what am I missing?

Upon running my python script I am getting following error

 File "myfile.py", line 538, in parse_format_views_into_memsource_json
   page_soup = BeautifulSoup(page, 'xml')
 File "C:Python27libsite-packagess4\__init__.py", line 246, in __init__
   % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: xml. Do you need to install a parser library?

After reading a few posting about bs4, I changed the xml to lxml like below.

page_soup = BeautifulSoup(page, 'lxml')

Now I am getting the same error for lxml

 File "myfile.py", line 538, in parse_format_views_into_memsource_json
   page_soup = BeautifulSoup(page, 'lxml')
 File "C:Python27libsite-packagess4\__init__.py", line 246, 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 am very puzzled about this situation. I checked my pip list and surely I do have lxml. The list below.

backports.functools-lru-cache (1.6.1)
backports.shutil-get-terminal-size (1.0.0)
beautifulsoup4 (4.9.3)
certifi (2018.1.18)
chardet (3.0.4)
colorama (0.3.9)
distribute (0.6.19)
idna (2.6)
Jinja2 (2.10)
Logbook (1.2.1)
lxml (4.6.2)
Mako (1.0.7)
MarkupSafe (1.0)
Myghty (1.2)
mysql-connector (2.2.9)
p4python (2017.2.1615960)
Paste (2.0.3)
PasteDeploy (1.5.2)
PasteScript (2.0.2)
pip (9.0.1)
psutil (5.4.3)
psycopg2 (2.7.4)
pymssql (2.1.3)
pyodbc (4.0.22)
pypm (1.3.4)
pythonselect (1.3)
pywin32 (214)
PyYAML (3.12)
RBTools (1.0.4.dev1)
repoze.lru (0.7)
requests (2.18.4)
Routes (2.4.1)
setuptools (38.4.0)
six (1.11.0)
soupsieve (1.9.6)
SQLAlchemy (1.2.2)
texttable (1.4.0)
tqdm (4.19.5)
urllib3 (1.22)
virtualenv (15.1.0)
wheel (0.30.0)

Am I missing anything here?

==== Update ===

I have checked import on lxml. Although I pip installed lxml, I cannot import lxml or lxml.etree. What makes more confusing is that I can import bs4 without any problem. I pip installed them at the same time and the same manner. I don't know how to proceed from here.

I checked the pip package list again, this time from the script itself using following command.

import pkg_resources
print([p.project_name for p in pkg_resources.working_set])

It clearly shows that there lxml is available the the Python instance I am using. Below is the output

['wsgiref', 'wheel', 'virtualenv', 'urllib3', 'tqdm', 'texttable', 'SQLAlchemy', 'soupsieve', 'six', 'setuptools', 'Routes', 'requests', 'repoze.lru', 'RBTools', 'PyYAML', 'pywin32', 'pythonselect', 'pypm', 'pyodbc', 'pymssql', 'psycopg2', 'psutil', 'pip', 'PasteScript', 'PasteDeploy', 'Paste', 'p4python', 'mysql-connector', 'Myghty', 'MarkupSafe', 'Mako', 'lxml', 'Logbook', 'Jinja2', 'idna', 'distribute', 'colorama', 'chardet', 'certifi', 'beautifulsoup4', 'backports.shutil-get-terminal-size', 'backports.functools-lru-cache']


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...