任何人都可以解释为什么我收到此错误[ImportError:找不到lxml,请安装它]

时间:2016-07-18 16:21:28

标签: python ubuntu pandas lxml html5lib

我正在尝试使用pandas库中的.read_html()函数,并在shell中运行代码时不断收到此错误。我看到你需要安装lxml所以我用apt-get做了。但后来当我试图再次运行时,我得到了同样的错误。

(trusty)mdz5032@localhost:~$ sudo apt-get -y install python-lxml
[sudo] password for mdz5032: 
Reading package lists... Done
.
.
.
python-lxml is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

以下是我正在使用的代码

import pandas as pd
import pandas_datareader.data as web
import quandl


df = quandl.get("FMAC/HPI_PA", authtoken="")

fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')

我取出了api密钥,但如果需要可以发布。

这是完整的追溯

Traceback (most recent call last):
  File "/home/mdz5032/pandasPractice.py", line 9, in <module>
    fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
  File "/usr/local/lib/python3.4/dist-packages/pandas/io/html.py", line 874, in read_html
    parse_dates, tupleize_cols, thousands, attrs, encoding)
  File "/usr/local/lib/python3.4/dist-packages/pandas/io/html.py", line 726, in _parse
    parser = _parser_dispatch(flav)
  File "/usr/local/lib/python3.4/dist-packages/pandas/io/html.py", line 685, in _parser_dispatch
    raise ImportError("lxml not found, please install it")
ImportError: lxml not found, please install it

1 个答案:

答案 0 :(得分:2)

sudo apt-get install python3-lxml

您已为python2安装了lxml,但您的代码在python3下运行。