我有以下代码(在PyCharm (MacOS)中):
import pandas as pd
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
print(fiddy_states)
我得到了以下错误:
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/user_name/PycharmProjects/PandasTest/Doc3.py
Traceback (most recent call last):
File "/Users/user_name/PycharmProjects/PandasTest/Doc3.py", line 9, in <module>
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/html.py", line 906, in read_html
keep_default_na=keep_default_na)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/html.py", line 733, in _parse
parser = _parser_dispatch(flav)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/html.py", line 693, in _parser_dispatch
raise ImportError("lxml not found, please install it")
ImportError: lxml not found, please install it
在Anaconda中,确实安装了最后一个版本的lxml
(3.8.0
)。尽管如此,我还是尝试通过以下方式重新安装它:1) writing pip install lxml
和2)下载与我的python版本(lxml-3.8.0-cp36-cp36m-win_amd64.whl
)相对应的lxml
轮子,但在任何情况下都保持不变(第二种情况是not a supported wheel on this platform
,尽管python的版本是正确的(3.6,64位))。
我在这里读过类似的问题(即使上面的代码与教程中的相同),但问题仍然存在。
发布于 2021-05-05 18:54:35
对于使用木星笔记本的人来说,我在pip install lxml
之后重新启动内核,错误就消失了。
发布于 2018-11-07 18:10:21
我也犯了同样的错误,我的python3似乎指向了python2中的熊猫(因为我没有在python3中安装熊猫)。在做了pip3安装熊猫和重新启动笔记本之后,它工作得很好。
发布于 2021-01-25 14:03:33
pip install lxml bs4 html5lib
pd.read_html()
使用'lxml‘库进行读取,因此请尝试安装在上面的另一个库,如pd.read_html(some_url, flavor='html5lib')
https://stackoverflow.com/questions/44954802
复制相似问题